-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
26 lines (24 loc) · 780 Bytes
/
index.js
File metadata and controls
26 lines (24 loc) · 780 Bytes
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
'use strict'
const util = require('util')
class Logger {
constructor(component) { // component is likely to corresponmd to a modeul, but does not have to
this.component = component;
}
_log(level, functionName, context, ...args) {
args.unshift(new Date().toISOString(), level, this.component, functionName, context['request-id'] || 'no-request-id', context.user || 'INCOGNITO')
console.log.apply(null, args.map(x=>typeof x == 'object' ? util.inspect(x,{depth: null}) : x))
}
info(...args) {
args.unshift('info')
this._log.apply(this,args)
}
debug(...args) {
args.unshift('debug')
this._log.apply(this, args)
}
error(...args) {
args.unshift('\x1b[30;101merror\x1b[0m')
this._log.apply(this, args)
}
}
exports.Logger = Logger