diff --git a/.env.example b/.env.example index f2d17f7d4..f5e6cf829 100644 --- a/.env.example +++ b/.env.example @@ -4,6 +4,12 @@ # Remove all line-comments and save this as .env to enable # Do not commit the filled-out file to GitHub +# possible values: all, trace, debug, info, warn, error, fatal, off (default: info) +LOG_LEVEL=debug + +# possible values: [unset], json, breif, verbose (default: unset) +LOG_FORMAT= + # Wix API key for import API_KEY= @@ -76,4 +82,4 @@ GAMIFICATION_ACTIVE= REQUIRE_PUPIL_SCREENING= # Credential for the OpenAI API to use their LLMs -OPENAI_API_KEY= \ No newline at end of file +OPENAI_API_KEY= diff --git a/common/logger/logger.ts b/common/logger/logger.ts index 00eccb2a9..9de8ed8a6 100644 --- a/common/logger/logger.ts +++ b/common/logger/logger.ts @@ -1,9 +1,8 @@ import tracer from './tracing'; import formats from 'dd-trace/ext/formats'; -import { isCommandArg } from '../util/basic'; import { configure, addLayout, getLogger as getlog4jsLogger, Logger as Log4jsLogger } from 'log4js'; import { getCurrentTransaction } from '../session'; -import { getServiceName, getHostname } from '../../utils/environment'; +import { getServiceName, getHostname, getLogLevel, getLogFormat } from '../../utils/environment'; addLayout('json', function () { return function (logEvent) { @@ -25,12 +24,13 @@ addLayout('json', function () { }; }); +const logFormat = getLogFormat(); let appenders = ['out']; -if (process.env.LOG_FORMAT === 'json') { +if (logFormat === 'json') { appenders = ['outJson']; -} else if (process.env.LOG_FORMAT === 'brief') { +} else if (logFormat === 'brief') { appenders = ['outBrief']; -} else if (process.env.LOG_FORMAT === 'verbose') { +} else if (logFormat === 'verbose') { appenders = ['outBrief', 'fileVerbose']; } @@ -83,7 +83,7 @@ configure({ categories: { default: { appenders, - level: isCommandArg('--debug') ? 'debug' : 'info', + level: getLogLevel('info'), }, }, diff --git a/utils/environment.ts b/utils/environment.ts index 4e556ed45..b78c987eb 100644 --- a/utils/environment.ts +++ b/utils/environment.ts @@ -25,3 +25,11 @@ export function isGamificationFeatureActive(): boolean { export function isWebflowSyncDryRun(): boolean { return JSON.parse(process.env.WEBFLOW_SYNC_DRY_RUN || 'true'); } + +export function getLogLevel(defaultLevel: string): string { + return process.env.LOG_LEVEL || defaultLevel; +} + +export function getLogFormat(): string | null { + return process.env.LOG_FORMAT; +}