Skip to content

Commit

Permalink
fix(logger): return undefined if file path not found
Browse files Browse the repository at this point in the history
  • Loading branch information
meenahoda committed Nov 30, 2021
1 parent 80edb3c commit 67a6a65
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions lib/plugin/components/services/logger/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Logger {
? process.env.LOGGER
: (process.env.LOGGER === '*' ? 'trace' : 'info')
this.loggerOutputFilePath = generateFilePath(process.env.LOGGER_OUTPUT_DIR_PATH)
options.messages.detail(this.loggerOutputFilePath ? `Output logs to ${this.loggerOutputFilePath}` : 'No output file')
options.messages.info(this.loggerOutputFilePath ? `Output logs to ${this.loggerOutputFilePath}` : 'No output file')
this.logger = this.createLogger()
}

Expand Down Expand Up @@ -47,8 +47,8 @@ class Logger {
}

function generateFilePath (dirpath) {
if (!dirpath) return {}
if (!fs.existsSync(dirpath)) return {}
if (!dirpath) return
if (!fs.existsSync(dirpath)) return

const now = moment()
const filename = `${now.format('YYYYMMDD-HHmm')}.log`
Expand Down Expand Up @@ -81,12 +81,9 @@ function generateFilePath (dirpath) {
// }

function createMultistream (filepath, level) {
const streams = [
{ stream: pino.destination(filepath), level }
]
if (process.env.NODE_ENV === 'development') {
streams.push({ stream: pinoPretty() })
}
const streams = []
if (filepath) streams.push({ stream: pino.destination(filepath), level })
if (process.env.NODE_ENV === 'development') streams.push({ stream: pinoPretty() })
return pino.multistream(streams)
}

Expand Down

0 comments on commit 67a6a65

Please sign in to comment.