forked from pinpoint-apm/pinpoint-node-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.js
63 lines (51 loc) · 1.12 KB
/
logger.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
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
/**
* Pinpoint Node.js Agent
* Copyright 2020-present NAVER Corp.
* Apache License v2.0
*/
'use strict'
const loglevel = require('loglevel')
class Logger {
constructor() {
this.LOG_LEVEL = loglevel.levels
this.DEFAULT_LEVEL = this.LOG_LEVEL.SILENT
this.DEFAULT_NAME = 'default_logger'
this.init()
}
init(logLevel, name) {
this.logger = loglevel.getLogger(name || this.DEFAULT_NAME)
this.logger.setLevel(logLevel || this.DEFAULT_LEVEL)
}
get log() {
if (!this.logger) {
this.init()
this.logger.info('init logger with default level')
}
return this.logger
}
debug() {
this.logger.debug.apply(null, arguments)
}
isDebug() {
if (!this.logger) {
return false
}
return this.logger.getLevel() == this.LOG_LEVEL.DEBUG
}
info() {
this.logger.info.apply(null, arguments)
}
isInfo() {
if (!this.logger) {
return false
}
return this.logger.getLevel() == this.LOG_LEVEL.INFO
}
warn() {
this.logger.warn.apply(null, arguments)
}
error() {
this.logger.error.apply(null, arguments)
}
}
module.exports = new Logger()