Skip to content

Commit

Permalink
Merge branch 'master' into snyk-fix-f267c82235b09e2ef5b6ef23c7c44bc4
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeknovy authored Dec 12, 2024
2 parents ece005b + d60d8b2 commit c7f1e50
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions src/logger.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,32 @@
import * as winston from "winston"

const LOG_LEVELS = winston.config.syslog.levels
const DEFAULT_LOG_LEVEL = "debug"

const getLogLevel = (): string => {
const logLevelEnvVar = process.env.LOG_LEVEL
if (logLevelEnvVar) {
const isAllowedLogLevel = Object.keys(LOG_LEVELS)
.find(level => logLevelEnvVar.toLowerCase() === level.toLowerCase())
if (!isAllowedLogLevel) {
console.log("Unsupported log level: ", logLevelEnvVar)
} else {
return isAllowedLogLevel
}
}
return DEFAULT_LOG_LEVEL


}

export const logger = winston.createLogger({
format: winston.format.combine(
winston.format.timestamp({ format: "YYYY-MM-DD HH:mm:ss" }),
winston.format.json()
),
levels: winston.config.syslog.levels,
transports: [ new winston.transports.Console() ],
format: winston.format.combine(
winston.format.timestamp({ format: "YYYY-MM-DD HH:mm:ss" }),
winston.format.json()
),
level: getLogLevel(),
levels: LOG_LEVELS,
transports: [new winston.transports.Console()],
})


0 comments on commit c7f1e50

Please sign in to comment.