74 lines
2.4 KiB
TypeScript
74 lines
2.4 KiB
TypeScript
/**
|
|
* Logging configuration using Yup
|
|
* Application logging settings without Loki (Loki config is in monitoring.ts)
|
|
*/
|
|
import { cleanEnv, envValidators } from './env-utils';
|
|
|
|
const { str, bool, num, strWithChoices } = envValidators;
|
|
|
|
/**
|
|
* Logging configuration with validation and defaults
|
|
*/
|
|
export const loggingConfig = cleanEnv(process.env, {
|
|
// Basic Logging Settings
|
|
LOG_LEVEL: strWithChoices(['debug', 'info', 'warn', 'error'], 'info', 'Logging level'),
|
|
LOG_FORMAT: strWithChoices(['json', 'simple', 'combined'], 'json', 'Log output format'),
|
|
LOG_CONSOLE: bool(true, 'Enable console logging'),
|
|
LOG_FILE: bool(false, 'Enable file logging'),
|
|
|
|
// File Logging Settings
|
|
LOG_FILE_PATH: str('logs', 'Log file directory path'),
|
|
LOG_FILE_MAX_SIZE: str('20m', 'Maximum log file size'),
|
|
LOG_FILE_MAX_FILES: num(14, 'Maximum number of log files to keep'),
|
|
LOG_FILE_DATE_PATTERN: str('YYYY-MM-DD', 'Log file date pattern'),
|
|
|
|
// Error Logging
|
|
LOG_ERROR_FILE: bool(true, 'Enable separate error log file'),
|
|
LOG_ERROR_STACK: bool(true, 'Include stack traces in error logs'),
|
|
|
|
// Performance Logging
|
|
LOG_PERFORMANCE: bool(false, 'Enable performance logging'),
|
|
LOG_SQL_QUERIES: bool(false, 'Log SQL queries'),
|
|
LOG_HTTP_REQUESTS: bool(true, 'Log HTTP requests'),
|
|
|
|
// Structured Logging
|
|
LOG_STRUCTURED: bool(true, 'Use structured logging format'),
|
|
LOG_TIMESTAMP: bool(true, 'Include timestamps in logs'),
|
|
LOG_CALLER_INFO: bool(false, 'Include caller information in logs'),
|
|
// Log Filtering
|
|
LOG_SILENT_MODULES: str('', 'Comma-separated list of modules to silence'),
|
|
LOG_VERBOSE_MODULES: str('', 'Comma-separated list of modules for verbose logging'),
|
|
|
|
// Application Context
|
|
LOG_SERVICE_NAME: str('stock-bot', 'Service name for log context'),
|
|
LOG_SERVICE_VERSION: str('1.0.0', 'Service version for log context'),
|
|
LOG_ENVIRONMENT: str('development', 'Environment for log context'),
|
|
});
|
|
|
|
// Export typed configuration object
|
|
export type LoggingConfig = typeof loggingConfig;
|
|
|
|
// Export individual config values for convenience
|
|
export const {
|
|
LOG_LEVEL,
|
|
LOG_FORMAT,
|
|
LOG_CONSOLE,
|
|
LOG_FILE,
|
|
LOG_FILE_PATH,
|
|
LOG_FILE_MAX_SIZE,
|
|
LOG_FILE_MAX_FILES,
|
|
LOG_FILE_DATE_PATTERN,
|
|
LOG_ERROR_FILE,
|
|
LOG_ERROR_STACK,
|
|
LOG_PERFORMANCE,
|
|
LOG_SQL_QUERIES,
|
|
LOG_HTTP_REQUESTS,
|
|
LOG_STRUCTURED,
|
|
LOG_TIMESTAMP,
|
|
LOG_CALLER_INFO,
|
|
LOG_SILENT_MODULES,
|
|
LOG_VERBOSE_MODULES,
|
|
LOG_SERVICE_NAME,
|
|
LOG_SERVICE_VERSION,
|
|
LOG_ENVIRONMENT,
|
|
} = loggingConfig;
|