feat: use LOG_LEVEL from env

This commit is contained in:
max_richter 2023-08-16 23:51:56 +02:00
parent 830b33462d
commit 5ee7adbd0a
2 changed files with 16 additions and 4 deletions

View File

@ -17,5 +17,8 @@ export const SESSION_DURATION = duration ? +duration : (60 * 60 * 24);
export const JWT_SECRET = Deno.env.get("JWT_SECRET");
export const TYPESENSE_URL = Deno.env.get("TYPESENSE_URL")||"http://localhost:8108"
export const TYPESENSE_API_KEY = Deno.env.get("TYPESENSE_API_KEY")
export const TYPESENSE_URL = Deno.env.get("TYPESENSE_URL") ||
"http://localhost:8108";
export const TYPESENSE_API_KEY = Deno.env.get("TYPESENSE_API_KEY");
export const LOG_LEVEL = Deno.env.get("LOG_LEVEL") || "warn";

View File

@ -1,4 +1,5 @@
import { EventEmitter } from "https://deno.land/x/evtemitter@v3.0.0/mod.ts";
import { EventEmitter } from "https://deno.land/x/evtemitter@v3.0.0/mod.ts"
import {LOG_LEVEL as _LOG_LEVEL} from "@lib/env.ts"
enum LOG_LEVEL {
DEBUG = 0,
@ -6,6 +7,14 @@ enum LOG_LEVEL {
WARN = 2,
ERROR = 3,
}
const logMap = {
"debug":LOG_LEVEL.DEBUG,
"info":LOG_LEVEL.INFO,
"warn":LOG_LEVEL.WARN,
"error":LOG_LEVEL.ERROR
} as const
const logFuncs = {
[LOG_LEVEL.DEBUG]: console.debug,
[LOG_LEVEL.INFO]: console.info,
@ -14,7 +23,7 @@ const logFuncs = {
} as const;
let longestScope = 0;
let logLevel = LOG_LEVEL.WARN;
let logLevel = (_LOG_LEVEL && _LOG_LEVEL in logMap && logMap[_LOG_LEVEL] )|| LOG_LEVEL.WARN;
const ee = new EventEmitter<{
log: { level: LOG_LEVEL; scope: string; args: unknown[] };