forked from pinpoint-apm/pinpoint-node-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/** | ||
* 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' | ||
} | ||
|
||
static get DebugBuilder() { | ||
return class Builder { | ||
constructor(name) { | ||
this.name = name | ||
this.level = LogLevel.levels.DEBUG | ||
} | ||
} | ||
} | ||
|
||
static get InfoBuilder() { | ||
return class Builder { | ||
constructor(name) { | ||
this.name = name | ||
this.level = LogLevel.levels.INFO | ||
} | ||
} | ||
} | ||
|
||
static get WarnBuilder() { | ||
return class Builder { | ||
constructor(name) { | ||
this.name = name | ||
this.level = LogLevel.levels.WARN | ||
} | ||
} | ||
} | ||
|
||
static get ErrorBuilder() { | ||
return class Builder { | ||
constructor(name) { | ||
this.name = name | ||
this.level = LogLevel.levels.ERROR | ||
} | ||
} | ||
} | ||
|
||
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() == LogLevel.levels.DEBUG | ||
} | ||
|
||
info() { | ||
this.logger.info.apply(null, arguments) | ||
} | ||
|
||
isInfo() { | ||
if (!this.logger) { | ||
return false | ||
} | ||
return this.logger.getLevel() == LogLevel.levels.INFO | ||
} | ||
|
||
warn() { | ||
this.logger.warn.apply(null, arguments) | ||
} | ||
|
||
error() { | ||
this.logger.error.apply(null, arguments) | ||
} | ||
} | ||
|
||
module.exports = Logger |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters