33 lines
		
	
	
		
			742 B
		
	
	
	
		
			TypeScript
		
	
	
			
		
		
	
	
			33 lines
		
	
	
		
			742 B
		
	
	
	
		
			TypeScript
		
	
	
| let _loggerdata = ""
 | |
| let _log = true
 | |
| 
 | |
| // define a new console
 | |
| const c=(function(oldCons){
 | |
|     return {
 | |
|         log: function(text){
 | |
|             if (_log) oldCons.log(text)
 | |
|             if (_loggerdata !== "") _loggerdata += "\n"
 | |
|             _loggerdata += text
 | |
|         },
 | |
|         info: function (text) {
 | |
|             oldCons.info(text)
 | |
|         },
 | |
|         warn: function (text) {
 | |
|             oldCons.warn(text)
 | |
|         },
 | |
|         error: function (text) {
 | |
|             oldCons.error(text)
 | |
|         },
 | |
|         start: function(log) {
 | |
|             _loggerdata = ""
 | |
|             _log = log
 | |
|         },
 | |
|         end: function() {
 | |
|             _log = true
 | |
|             return _loggerdata
 | |
|         }
 | |
|     }
 | |
| }(console))
 | |
| 
 | |
| //Then redefine the old console
 | |
| console = c |