Skip to content

Commit

Permalink
✨ Allow LogLevel customization through env var
Browse files Browse the repository at this point in the history
  • Loading branch information
pvillaverde committed May 20, 2024
1 parent 00ffff2 commit dd7bc8c
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/services/logger.service.ts
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",
});
});

0 comments on commit dd7bc8c

Please sign in to comment.