import { type LevelName, LogLevels, } from "https://deno.land/std@0.159.0/log/mod.ts"; export interface Config { log: { consoleLevelName: LevelName; }; postgres: { url: string; }; mailgun: { apiKey?: string; domain?: string; }; } function envOrWarn(key: string, fallback: string): string { const val = Deno.env.get(key); if (!val) console.warn(`${key} is not set! Using fallback: ${fallback}`); return val || fallback; } function isLogLevelName(s: string): s is LevelName { return s in LogLevels; } const desiredLogLevel = envOrWarn("LOG_LEVEL", "INFO").toUpperCase(); if (!isLogLevelName(desiredLogLevel)) { console.warn( `Desired LOG_LEVEL of '${desiredLogLevel}' is invalid. Falling back to 'INFO'`, ); } const logLevel: LevelName = isLogLevelName(desiredLogLevel) ? desiredLogLevel : "INFO"; export const config: Config = { log: { consoleLevelName: logLevel, }, postgres: { url: envOrWarn( "POSTGRES_URL", "postgresql://postgres:@127.0.0.1:5432/lyricscreen", ), }, mailgun: {}, };