mirror of
https://github.com/simstudioai/sim.git
synced 2026-04-06 03:00:16 -04:00
improvement(log-level): make log level configurable via envvar (#1091)
This commit is contained in:
@@ -81,6 +81,7 @@ export const env = createEnv({
|
||||
SENTRY_ORG: z.string().optional(), // Sentry organization for error tracking
|
||||
SENTRY_PROJECT: z.string().optional(), // Sentry project for error tracking
|
||||
SENTRY_AUTH_TOKEN: z.string().optional(), // Sentry authentication token
|
||||
LOG_LEVEL: z.enum(['DEBUG', 'INFO', 'WARN', 'ERROR']).optional(), // Minimum log level to display (defaults to ERROR in production, DEBUG in development)
|
||||
|
||||
// External Services
|
||||
JWT_SECRET: z.string().min(1).optional(), // JWT signing secret for custom tokens
|
||||
|
||||
@@ -29,6 +29,30 @@ export enum LogLevel {
|
||||
ERROR = 'ERROR',
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the minimum log level from environment variable or use defaults
|
||||
* - Development: DEBUG (show all logs)
|
||||
* - Production: ERROR (only show errors, but can be overridden by LOG_LEVEL env var)
|
||||
* - Test: ERROR (only show errors in tests)
|
||||
*/
|
||||
const getMinLogLevel = (): LogLevel => {
|
||||
if (env.LOG_LEVEL) {
|
||||
return env.LOG_LEVEL as LogLevel
|
||||
}
|
||||
|
||||
const ENV = (env.NODE_ENV || 'development') as string
|
||||
switch (ENV) {
|
||||
case 'development':
|
||||
return LogLevel.DEBUG
|
||||
case 'production':
|
||||
return LogLevel.ERROR
|
||||
case 'test':
|
||||
return LogLevel.ERROR
|
||||
default:
|
||||
return LogLevel.DEBUG
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configuration for different environments
|
||||
*
|
||||
@@ -40,17 +64,17 @@ export enum LogLevel {
|
||||
const LOG_CONFIG = {
|
||||
development: {
|
||||
enabled: true,
|
||||
minLevel: LogLevel.DEBUG, // Show all logs in development
|
||||
minLevel: getMinLogLevel(),
|
||||
colorize: true,
|
||||
},
|
||||
production: {
|
||||
enabled: true, // Will be checked at runtime
|
||||
minLevel: LogLevel.ERROR,
|
||||
minLevel: getMinLogLevel(),
|
||||
colorize: false,
|
||||
},
|
||||
test: {
|
||||
enabled: false, // Disable logs in test environment
|
||||
minLevel: LogLevel.ERROR,
|
||||
minLevel: getMinLogLevel(),
|
||||
colorize: false,
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user