Skip to content

Commit

Permalink
[pinpoint-apm#117] logger loading time
Browse files Browse the repository at this point in the history
  • Loading branch information
feelform committed Oct 20, 2022
1 parent dc863d6 commit 1a8d8fa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
14 changes: 10 additions & 4 deletions lib/supports.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
const Logger = require('./utils/log/logger2')
const { getConfig, needsLoadConfig } = require('./config')

const log = new Logger.NoneBuilder({
const noneConfigurationLog = new Logger.NoneBuilder({
logs: [],
debug: function (message) {
this.logs.push(message)
Expand All @@ -25,15 +25,21 @@ const log = new Logger.NoneBuilder({
}
}).build()

let log = undefined
module.exports = {
getLog: function () {
if (needsLoadConfig()) {
if (log) {
return log
}

const config = getConfig()
if (config.logLevel) {
if (needsLoadConfig()) {
return noneConfigurationLog
}

const config = getConfig()
if (!log) {
log = Logger.makeBuilder(config.logLevel, {}).build()
}
return log
}
}
1 change: 1 addition & 0 deletions test/utils/log/logger.integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ test('Logger Adaptor', (t) => {
const actual = getLog()
new Agent()
t.equal(actual.adaptor.constructor.name, 'LoggerOutputAdaptor', 'log adaptor')
t.equal(actual.type.name, 'NONE', 'when first loading time, log type is NONE')
t.end()
})

0 comments on commit 1a8d8fa

Please sign in to comment.