mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 02:55:58 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			38 lines
		
	
	
		
			652 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			38 lines
		
	
	
		
			652 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| 'use strict';
 | |
| 
 | |
| var winston = require('winston');
 | |
| var Transport = require('winston-transport');
 | |
| 
 | |
| var winstonLogged = [];
 | |
| 
 | |
| class DeferLogger extends Transport {
 | |
| 	constructor(opts) {
 | |
| 		super(opts);
 | |
| 		this.logged = opts.logged;
 | |
| 	}
 | |
| 
 | |
| 	log(info, callback) {
 | |
| 		setImmediate(() => {
 | |
| 			this.emit('logged', info);
 | |
| 		});
 | |
| 
 | |
| 		this.logged.push([info.level, info.message]);
 | |
| 		callback();
 | |
| 	}
 | |
| }
 | |
| 
 | |
| before(function () {
 | |
| 	// defer winston logs until the end
 | |
| 	winston.clear();
 | |
| 
 | |
| 	winston.add(new DeferLogger({ logged: winstonLogged }));
 | |
| });
 | |
| 
 | |
| after(function () {
 | |
| 	console.log('\n\n');
 | |
| 
 | |
| 	winstonLogged.forEach(function (args) {
 | |
| 		console.log(args[0] + ' ' + args[1]);
 | |
| 	});
 | |
| });
 |