| 
									
										
										
										
											2017-05-09 22:20:40 -06:00
										 |  |  | 'use strict'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var winston = require('winston'); | 
					
						
							| 
									
										
										
										
											2018-10-16 13:07:13 -04:00
										 |  |  | var Transport = require('winston-transport'); | 
					
						
							| 
									
										
										
										
											2017-05-09 22:20:40 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-16 13:07:13 -04:00
										 |  |  | var winstonLogged = []; | 
					
						
							| 
									
										
										
										
											2017-05-09 22:20:40 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-16 13:07:13 -04:00
										 |  |  | class DeferLogger extends Transport { | 
					
						
							|  |  |  | 	constructor(opts) { | 
					
						
							|  |  |  | 		super(opts); | 
					
						
							|  |  |  | 		this.logged = opts.logged; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-05-09 22:20:40 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-16 13:07:13 -04:00
										 |  |  | 	log(info, callback) { | 
					
						
							|  |  |  | 		setImmediate(() => { | 
					
						
							|  |  |  | 			this.emit('logged', info); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-05-09 22:20:40 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-16 13:07:13 -04:00
										 |  |  | 		this.logged.push([info.level, info.message]); | 
					
						
							|  |  |  | 		callback(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-05-09 22:20:40 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | before(function () { | 
					
						
							|  |  |  | 	// defer winston logs until the end
 | 
					
						
							| 
									
										
										
										
											2018-10-16 13:07:13 -04:00
										 |  |  | 	winston.clear(); | 
					
						
							| 
									
										
										
										
											2017-05-09 22:20:40 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-16 13:07:13 -04:00
										 |  |  | 	winston.add(new DeferLogger({ logged: winstonLogged })); | 
					
						
							| 
									
										
										
										
											2017-05-09 22:20:40 -06:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | after(function () { | 
					
						
							|  |  |  | 	console.log('\n\n'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	winstonLogged.forEach(function (args) { | 
					
						
							| 
									
										
										
										
											2018-10-16 13:07:13 -04:00
										 |  |  | 		console.log(args[0] + ' ' + args[1]); | 
					
						
							| 
									
										
										
										
											2017-05-09 22:20:40 -06:00
										 |  |  | 	}); | 
					
						
							|  |  |  | }); |