-
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.
✨ Allow LogLevel customization through env var
- Loading branch information
1 parent
00ffff2
commit dd7bc8c
Showing
1 changed file
with
20 additions
and
2 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 |
---|---|---|
@@ -1,6 +1,24 @@ | ||
import { Logger } from "npm:tslog"; | ||
import LogLevel from "../types/logLevel.ts"; | ||
|
||
// Create a mapping of log level strings to LogLevel enum values | ||
const logLevelMap: { [key: string]: LogLevel } = { | ||
silly: LogLevel.Silly, | ||
trace: LogLevel.Trace, | ||
debug: LogLevel.Debug, | ||
info: LogLevel.Info, | ||
warn: LogLevel.Warn, | ||
error: LogLevel.Error, | ||
fatal: LogLevel.Fatal, | ||
}; | ||
|
||
// Function to get the log level from the environment variable | ||
function getLogLevelFromEnv(): LogLevel { | ||
const logLevelString = Deno.env.get("LOG_LEVEL")?.toLowerCase() || "info"; | ||
return logLevelMap[logLevelString] ?? LogLevel.Info; | ||
} | ||
|
||
export default new Logger({ | ||
minLevel: LogLevel.Info, | ||
minLevel: getLogLevelFromEnv(), | ||
type: "pretty", | ||
}); | ||
}); |