-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
85 lines (69 loc) · 1.75 KB
/
index.js
File metadata and controls
85 lines (69 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
'use strict';
const Console = require('console').Console;
const EE = require('events').EventEmitter;
const winston = require('winston');
const intel = require('intel');
const pino = require('pino');
const log4js = require('log4js').getLogger();
const stdout = new EE();
stdout.write = function (out, encoding, cb) {
if (typeof encoding === 'function') {
cb = encoding;
encoding = null;
}
cb && cb();
return true;
};
winston.add(winston.transports.File, {stream: stdout, timestamp: true});
winston.remove(winston.transports.Console);
intel.addHandler(new intel.handlers.Stream(
{
level: intel.TRACE,
stream: stdout,
formatter: new intel.Formatter({
'format': '[%(date)s] %(name)s.%(levelname)s: %(message)s'
})
}
));
const plog = pino(
{
level: 'trace',
name: 'root'
},
stdout
);
const _console = new Console(stdout, stdout);
log4js.level = 'trace';
process.stdout.write = function(msg, enc, callback) {
if(typeof enc === 'function' && !callback) callback = enc;
callback && callback();
return true;
}
const Benchmark = require('benchmark');
const suite = new Benchmark.Suite('logging.info()');
suite
.add('console.info', function() {
_console.info('bench');
})
.add('winston.info', function() {
winston.info('bench');
})
.add('intel.info', function() {
intel.info('bench');
})
.add('pino.info', function() {
plog.info('bench');
})
.add('log4js.info', function() {
log4js.info('bench');
})
suite
// add listeners
.on('cycle', function (event) {
console.warn(String(event.target));
})
.on('complete', function () {
console.warn('Fastest is ' + this.filter('fastest').map('name'));
})
// run async
.run({ 'async': true });