switched to log from logging

This commit is contained in:
Boki 2025-06-20 19:43:56 -04:00
parent 9065937d2c
commit 24680e403d
6 changed files with 44 additions and 34 deletions

2
.env
View file

@ -4,7 +4,7 @@
# Core Application Settings # Core Application Settings
NODE_ENV=development NODE_ENV=development
LOG_LEVEL=debug LOG_LEVEL=error
# Data Service Configuration # Data Service Configuration
DATA_SERVICE_PORT=2001 DATA_SERVICE_PORT=2001

View file

@ -23,10 +23,10 @@ const databaseConfig = config.database;
const queueConfig = config.queue; const queueConfig = config.queue;
// Initialize logger with config // Initialize logger with config
const loggingConfig = config.logging; const logConfig = config.log;
if (loggingConfig) { if (logConfig) {
setLoggerConfig({ setLoggerConfig({
logLevel: loggingConfig.level, logLevel: logConfig.level,
logConsole: true, logConsole: true,
logFile: false, logFile: false,
environment: config.environment, environment: config.environment,

View file

@ -101,8 +101,13 @@ export function getServiceConfig() {
return getConfig().service; return getConfig().service;
} }
export function getLogConfig() {
return getConfig().log;
}
// Deprecated alias for backward compatibility
export function getLoggingConfig() { export function getLoggingConfig() {
return getConfig().logging; return getConfig().log;
} }
export function getProviderConfig(provider: string) { export function getProviderConfig(provider: string) {

View file

@ -174,8 +174,12 @@ export class EnvLoader implements ConfigLoader {
'NAME': ['name'], 'NAME': ['name'],
'VERSION': ['version'], 'VERSION': ['version'],
// Logging mappings // Log mappings (using LOG_ prefix for all)
'LOG_LEVEL': ['logging', 'level'], 'LOG_LEVEL': ['log', 'level'],
'LOG_FORMAT': ['log', 'format'],
'LOG_LOKI_ENABLED': ['log', 'loki', 'enabled'],
'LOG_LOKI_HOST': ['log', 'loki', 'host'],
'LOG_LOKI_PORT': ['log', 'loki', 'port'],
// Special mappings to avoid conflicts // Special mappings to avoid conflicts
'DEBUG_MODE': ['debug'], 'DEBUG_MODE': ['debug'],

View file

@ -70,8 +70,8 @@ const flexibleDatabaseConfigSchema = z.object({
}).default({}), }).default({}),
}).default({}); }).default({});
// Flexible logging schema with defaults // Flexible log schema with defaults (renamed from logging)
const flexibleLoggingConfigSchema = z.object({ const flexibleLogConfigSchema = z.object({
level: z.enum(['trace', 'debug', 'info', 'warn', 'error', 'fatal']).default('info'), level: z.enum(['trace', 'debug', 'info', 'warn', 'error', 'fatal']).default('info'),
format: z.enum(['json', 'pretty']).default('json'), format: z.enum(['json', 'pretty']).default('json'),
loki: z.object({ loki: z.object({
@ -86,7 +86,7 @@ const flexibleLoggingConfigSchema = z.object({
export const appConfigSchema = baseConfigSchema.extend({ export const appConfigSchema = baseConfigSchema.extend({
environment: environmentSchema.default('development'), environment: environmentSchema.default('development'),
service: flexibleServiceConfigSchema, service: flexibleServiceConfigSchema,
logging: flexibleLoggingConfigSchema, log: flexibleLogConfigSchema,
database: flexibleDatabaseConfigSchema, database: flexibleDatabaseConfigSchema,
queue: queueConfigSchema.optional(), queue: queueConfigSchema.optional(),
http: httpConfigSchema.optional(), http: httpConfigSchema.optional(),

View file

@ -54,6 +54,8 @@ function createTransports(serviceName: string, config: LoggerConfig = globalConf
ignore: 'pid,hostname,service,environment,version,childName', ignore: 'pid,hostname,service,environment,version,childName',
errorLikeObjectKeys: ['err', 'error'], errorLikeObjectKeys: ['err', 'error'],
errorProps: 'message,stack,name,code', errorProps: 'message,stack,name,code',
// Ensure the transport respects the configured level
minimumLevel: config.logLevel || 'info',
}, },
}); });
} }
@ -317,36 +319,35 @@ export async function shutdownLoggers(): Promise<void> {
} }
// Flush all loggers // Flush all loggers
const flushPromises = Array.from(loggerCache.values()).map(logger => { const flushPromises = Array.from(loggerCache.values()).map(logger => logger.flush());
return new Promise<void>((resolve) => { // return new Promise<void>((resolve) => {
// First try to flush if the method exists // // First try to flush if the method exists
if (typeof logger.flush === 'function') { // if (typeof logger.flush === 'function') {
const timeout = setTimeout(() => { // const timeout = setTimeout(() => {
// eslint-disable-next-line no-console // // eslint-disable-next-line no-console
console.warn('Logger flush timeout after 100ms'); // console.warn('Logger flush timeout after 100ms');
resolve(); // resolve();
}, 100); // }, 100);
logger.flush((err) => { // logger.flush((err) => {
clearTimeout(timeout); // clearTimeout(timeout);
if (err) { // if (err) {
// eslint-disable-next-line no-console // // eslint-disable-next-line no-console
console.error('Logger flush error:', err); // console.error('Logger flush error:', err);
} // }
resolve(); // resolve();
}); // });
} else { // } else {
resolve(); // resolve();
} // }
}); // });
}); // });
await Promise.all(flushPromises); await Promise.all(flushPromises);
// Give transports time to finish writing // Give transports time to finish writing
// This is especially important for file and network transports // This is especially important for file and network transports
await new Promise(resolve => setTimeout(resolve, 100)); await new Promise(resolve => setTimeout(resolve, 100));
} catch (error) { } catch (error) {
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
console.error('Logger shutdown failed:', error); console.error('Logger shutdown failed:', error);