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.
[pinpoint-apm#117] Support logger, authentication adaptor pattern
typescript tools support for .d.ts * https://nodejs.org/api/modules.html#enabling * fix license convention by https://docs.npmjs.com/cli/v8/configuring-npm/package-json#license Logger Adaptor pattern * The Logger must implements pinpoint.json config loading status and a log level. * support integration test * if adaptor doesn't have adaptor outer method, Agent outs logs to console
- Loading branch information
Showing
21 changed files
with
558 additions
and
59 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
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
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
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
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
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,11 @@ | ||
const SequenceGenerator = require('./sequence-generator') | ||
|
||
module.exports = { | ||
transactionIdGenerator: new SequenceGenerator(), | ||
asyncIdGenerator: new SequenceGenerator(1), | ||
stringMetaCacheKeyGenerator: new SequenceGenerator(1), | ||
apiMetaCacheKeyGenerator: new SequenceGenerator(1), | ||
pingIdGenerator: new SequenceGenerator(), | ||
dummyIdGenerator: new SequenceGenerator(), | ||
} | ||
|
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
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
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
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 |
---|---|---|
|
@@ -104,3 +104,4 @@ module.exports = function (agent, version, mysql2) { | |
} | ||
} | ||
} | ||
} |
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,45 @@ | ||
/** | ||
* Pinpoint Node.js Agent | ||
* Copyright 2022-present NAVER Corp. | ||
* Apache License v2.0 | ||
*/ | ||
|
||
'use strict' | ||
|
||
const Logger = require('./utils/log/logger2') | ||
const { getConfig, needsLoadConfig } = require('./config') | ||
|
||
const noneConfigurationLog = new Logger.NoneBuilder({ | ||
output: console, | ||
debug: function (message) { | ||
this.output.debug(message) | ||
}, | ||
info: function (message) { | ||
this.output.info(message) | ||
}, | ||
warn: function (message) { | ||
this.output.warn(message) | ||
}, | ||
error: function (message) { | ||
this.output.error(message) | ||
} | ||
}).build() | ||
|
||
let log = undefined | ||
module.exports = { | ||
getLog: function () { | ||
if (log) { | ||
return log | ||
} | ||
|
||
if (needsLoadConfig()) { | ||
return noneConfigurationLog | ||
} | ||
|
||
const config = getConfig() | ||
if (!log) { | ||
log = Logger.makeBuilder(config.logLevel, {}).build() | ||
} | ||
return log | ||
} | ||
} |
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,63 @@ | ||
/** | ||
* Pinpoint Node.js Agent | ||
* Copyright 2022-present NAVER Corp. | ||
* Apache License v2.0 | ||
*/ | ||
|
||
'use strict' | ||
|
||
class LoggerOutputAdaptor { | ||
constructor(output) { | ||
this.output = output | ||
} | ||
|
||
get console() { | ||
return console | ||
} | ||
|
||
debug(message) { | ||
if (!this.output || typeof this.output.debug != 'function') { | ||
if (typeof this.output.error === 'function') { | ||
this.output.error("The Adaptor doesn't has the debug function.") | ||
} else { | ||
this.console.error("The Adaptor doesn't has the debug function.") | ||
} | ||
return | ||
} | ||
this.output.debug(message) | ||
} | ||
|
||
info(message) { | ||
if (!this.output || typeof this.output.info != 'function') { | ||
if (typeof this.output.error === 'function') { | ||
this.output.error("The Adaptor doesn't has the info function.") | ||
} else { | ||
this.console.error("The Adaptor doesn't has the info function.") | ||
} | ||
return | ||
} | ||
this.output.info(message) | ||
} | ||
|
||
warn(message) { | ||
if (!this.output || typeof this.output.warn != 'function') { | ||
if (typeof this.output.error === 'function') { | ||
this.output.error("The Adaptor doesn't has the warn function.") | ||
} else { | ||
this.console.error("The Adaptor doesn't has the warn function.") | ||
} | ||
return | ||
} | ||
this.output.warn(message) | ||
} | ||
|
||
error(message) { | ||
if (!this.output || typeof this.output.error != 'function') { | ||
this.console.error("The Adaptor doesn't has the error function.") | ||
return | ||
} | ||
this.output.error(message) | ||
} | ||
} | ||
|
||
module.exports = LoggerOutputAdaptor |
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,128 @@ | ||
/** | ||
* Pinpoint Node.js Agent | ||
* Copyright 2020-present NAVER Corp. | ||
* Apache License v2.0 | ||
*/ | ||
|
||
'use strict' | ||
|
||
const LoggerOutputAdaptor = require('./logger-output-adaptor') | ||
|
||
class Logger { | ||
|
||
constructor(type, adaptor) { | ||
this.type = type | ||
this.adaptor = new LoggerOutputAdaptor(adaptor) | ||
} | ||
|
||
static get DebugBuilder() { | ||
return Logger.Builder(LogType.debug) | ||
} | ||
|
||
static Builder(type) { | ||
return class Builder { | ||
constructor(adaptor) { | ||
this.type = type | ||
this.adaptor = adaptor | ||
} | ||
|
||
build() { | ||
return new Logger(this.type, this.adaptor) | ||
} | ||
} | ||
} | ||
|
||
static get InfoBuilder() { | ||
return Logger.Builder(LogType.info) | ||
} | ||
|
||
static get WarnBuilder() { | ||
return Logger.Builder(LogType.warn) | ||
} | ||
|
||
static get ErrorBuilder() { | ||
return Logger.Builder(LogType.error) | ||
} | ||
|
||
static get NoneBuilder() { | ||
return Logger.Builder(LogType.noneConfig) | ||
} | ||
|
||
static makeBuilder(name, adaptor) { | ||
return new (Logger.Builder(LogType.valueOf(name)))(adaptor) | ||
} | ||
|
||
debug(message) { | ||
this.adaptor.debug(message) | ||
} | ||
|
||
isDebug() { | ||
return this.type.isDebug() | ||
} | ||
|
||
info(message) { | ||
this.adaptor.info(message) | ||
} | ||
|
||
isInfo() { | ||
return this.type.isInfo() | ||
} | ||
|
||
warn(message) { | ||
this.adaptor.warn(message) | ||
} | ||
|
||
error(message) { | ||
this.adaptor.error(message) | ||
} | ||
} | ||
|
||
class LogType { | ||
|
||
static get debug() { | ||
return new LogType('DEBUG') | ||
} | ||
|
||
static get info() { | ||
return new LogType('INFO') | ||
} | ||
|
||
static get warn() { | ||
return new LogType('WARN') | ||
} | ||
|
||
static get error() { | ||
return new LogType('ERROR') | ||
} | ||
|
||
static get noneConfig() { | ||
return new LogType('NONE') | ||
} | ||
|
||
static valueOf(name) { | ||
if (name.toUpperCase) { | ||
name = name.toUpperCase() | ||
} | ||
const type = [this.debug, this.info, this.warn, this.error].find(element => element.name === name) | ||
if (!type) { | ||
return this.noneConfig | ||
} | ||
|
||
return type | ||
} | ||
|
||
constructor(name) { | ||
this.name = name | ||
} | ||
|
||
isDebug() { | ||
return this.name === LogType.debug.name | ||
} | ||
|
||
isInfo() { | ||
return this.name === LogType.info.name | ||
} | ||
} | ||
|
||
|
||
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
Oops, something went wrong.