-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcustom-tags.js
33 lines (23 loc) · 1.24 KB
/
custom-tags.js
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
/* ------------------------------------------------------------------------ */
// NB: these packages are part of Ololog, no need to install them separately
const bullet = require ('string.bullet')
const { cyan, yellow, red, dim } = require ('ansicolor')
/* ------------------------------------------------------------------------ */
const log = require ('ololog').configure ({
locate: false,
time: true,
tag: (lines, {
level = '',
levelColor = { 'info': cyan, 'warn': yellow, 'error': red.bright.inverse, 'debug':blue },
clusterId
}) => {
const clusterStr = clusterId ? ('CLUSTER[' + (clusterId + '').padStart (2, '0') + ']') : ''
const levelStr = level && (levelColor[level] || (s => s)) (level.toUpperCase ())
return bullet (dim (clusterStr.padStart (10)) + '\t' + levelStr.padStart (6) + '\t', lines)
}
})
/* ------------------------------------------------------------------------ */
log.configure ({ tag: { clusterId: 1 } }) ('foo')
log.configure ({ tag: { clusterId: 3 } }).info ('bar')
log.configure ({ tag: { clusterId: 27 } }).error ('a multiline\nerror\nmessage')
/* ------------------------------------------------------------------------ */