-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbufflog.ts
More file actions
73 lines (59 loc) · 2.03 KB
/
bufflog.ts
File metadata and controls
73 lines (59 loc) · 2.03 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
import tracer from "dd-trace";
import formats from "dd-trace/ext/formats";
export class BuffLog {
pinoLogger: any;
defaultLevel = 'notice';
dest: any;
constructor() {
this.dest = require('pino').destination('/tmp/test.log')
this.dest[Symbol.for('pino.metadata')] = true
this.pinoLogger = require('pino')({
level: this.defaultLevel,
// probably we want to call it `msg`. if so, let's change the PHP library instead
messageKey: 'message',
// Define "base" fields
// soon: remove the `v` field https://github.com/pinojs/pino/issues/620
base: {},
// notice doesn't exist in pino, let's add it
customLevels: {
notice: 35
},
mixin () {
// Check here if a current trace exist to inject it in the log
// `tracer` is a singleton, will no-op if no tracer was initialized
var span = tracer.scope().active()
if (span) {
const traceInfo = {}
tracer.inject(span.context(), formats.LOG, traceInfo);
return traceInfo;
} else {
return {}
}
}
}, this.dest)
};
debug(message: string) {
this.pinoLogger.debug(message);
}
info(message: string) {
this.pinoLogger.info(message);
}
notice(message: string) {
this.pinoLogger.notice(message);
const { lastMsg, lastLevel, lastObj, lastTime} = this.dest
console.log(
'Logged message "%s" at level %d with object %o at time %s',
lastMsg, lastLevel, lastObj, lastTime
);
}
warning(message: string) {
this.pinoLogger.warn(message);
}
error(message: string) {
this.pinoLogger.error(message);
}
// for consistency with php-bufflog, critical == fatal
critical(message: string) {
this.pinoLogger.fatal(message);
}
}