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
NODE_ENV=development
LOG_LEVEL=debug
LOG_LEVEL=error
# Data Service Configuration
DATA_SERVICE_PORT=2001

View file

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

View file

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

View file

@ -174,8 +174,12 @@ export class EnvLoader implements ConfigLoader {
'NAME': ['name'],
'VERSION': ['version'],
// Logging mappings
'LOG_LEVEL': ['logging', 'level'],
// Log mappings (using LOG_ prefix for all)
'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
'DEBUG_MODE': ['debug'],

View file

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

View file

@ -54,6 +54,8 @@ function createTransports(serviceName: string, config: LoggerConfig = globalConf
ignore: 'pid,hostname,service,environment,version,childName',
errorLikeObjectKeys: ['err', 'error'],
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
const flushPromises = Array.from(loggerCache.values()).map(logger => {
return new Promise<void>((resolve) => {
// First try to flush if the method exists
if (typeof logger.flush === 'function') {
const timeout = setTimeout(() => {
// eslint-disable-next-line no-console
console.warn('Logger flush timeout after 100ms');
resolve();
}, 100);
const flushPromises = Array.from(loggerCache.values()).map(logger => logger.flush());
// return new Promise<void>((resolve) => {
// // First try to flush if the method exists
// if (typeof logger.flush === 'function') {
// const timeout = setTimeout(() => {
// // eslint-disable-next-line no-console
// console.warn('Logger flush timeout after 100ms');
// resolve();
// }, 100);
logger.flush((err) => {
clearTimeout(timeout);
if (err) {
// eslint-disable-next-line no-console
console.error('Logger flush error:', err);
}
resolve();
});
} else {
resolve();
}
});
});
// logger.flush((err) => {
// clearTimeout(timeout);
// if (err) {
// // eslint-disable-next-line no-console
// console.error('Logger flush error:', err);
// }
// resolve();
// });
// } else {
// resolve();
// }
// });
// });
await Promise.all(flushPromises);
// Give transports time to finish writing
// This is especially important for file and network transports
await new Promise(resolve => setTimeout(resolve, 100));
} catch (error) {
// eslint-disable-next-line no-console
console.error('Logger shutdown failed:', error);