fixed log levels
This commit is contained in:
parent
01e0fab0df
commit
8edd78a341
3 changed files with 33 additions and 30 deletions
|
|
@ -157,7 +157,7 @@ async function initializeServices() {
|
||||||
const jobData = {
|
const jobData = {
|
||||||
handler: handlerName,
|
handler: handlerName,
|
||||||
operation: scheduledJob.operation,
|
operation: scheduledJob.operation,
|
||||||
...(scheduledJob.payload || {}),
|
payload: scheduledJob.payload || {},
|
||||||
};
|
};
|
||||||
|
|
||||||
// Build job options from scheduled job config
|
// Build job options from scheduled job config
|
||||||
|
|
|
||||||
|
|
@ -70,9 +70,15 @@ export function initializeQMProvider() {
|
||||||
{
|
{
|
||||||
type: 'qm-maintnance',
|
type: 'qm-maintnance',
|
||||||
operation: 'spider-symbol-search',
|
operation: 'spider-symbol-search',
|
||||||
|
payload: {
|
||||||
|
prefix: null,
|
||||||
|
depth: 1,
|
||||||
|
source: 'qm',
|
||||||
|
maxDepth: 4
|
||||||
|
},
|
||||||
cronPattern: '0 0 * * 0', // Every Sunday at midnight
|
cronPattern: '0 0 * * 0', // Every Sunday at midnight
|
||||||
priority: 10,
|
priority: 10,
|
||||||
immediately: true, // Don't run on startup
|
immediately: true, // Don't run on startup - this is a heavy operation
|
||||||
description: 'Comprehensive symbol search using QM API',
|
description: 'Comprehensive symbol search using QM API',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
|
||||||
|
|
@ -25,15 +25,22 @@ let globalConfig: LoggerConfig = {
|
||||||
environment: 'development',
|
environment: 'development',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Log level priorities for comparison
|
||||||
|
const LOG_LEVELS: Record<LogLevel, number> = {
|
||||||
|
trace: 10,
|
||||||
|
debug: 20,
|
||||||
|
info: 30,
|
||||||
|
warn: 40,
|
||||||
|
error: 50,
|
||||||
|
fatal: 60,
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set global logger configuration
|
* Set global logger configuration
|
||||||
*/
|
*/
|
||||||
export function setLoggerConfig(config: LoggerConfig): void {
|
export function setLoggerConfig(config: LoggerConfig): void {
|
||||||
globalConfig = { ...globalConfig, ...config };
|
globalConfig = { ...globalConfig, ...config };
|
||||||
// Clear cache to force recreation with new config
|
|
||||||
loggerCache.clear();
|
loggerCache.clear();
|
||||||
// eslint-disable-next-line no-console
|
|
||||||
console.log('Logger config updated:', globalConfig.logLevel);
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Create logger destination using multistream approach:
|
* Create logger destination using multistream approach:
|
||||||
|
|
@ -49,12 +56,12 @@ function createDestination(
|
||||||
// Console: In-process pretty stream for dev (fast shutdown)
|
// Console: In-process pretty stream for dev (fast shutdown)
|
||||||
if (config.logConsole && config.environment !== 'production') {
|
if (config.logConsole && config.environment !== 'production') {
|
||||||
const prettyStream = pretty({
|
const prettyStream = pretty({
|
||||||
sync: true,
|
sync: false, // IMPORTANT: Make async to prevent blocking the event loop
|
||||||
colorize: true,
|
colorize: true,
|
||||||
translateTime: 'yyyy-mm-dd HH:MM:ss.l',
|
translateTime: 'yyyy-mm-dd HH:MM:ss.l',
|
||||||
messageFormat: '[{service}{childName}] {msg}',
|
messageFormat: '[{service}{childName}] {msg}',
|
||||||
singleLine: false, // This was causing logs to be on one line
|
singleLine: false, // This was causing logs to be on one line
|
||||||
hideObject: true, // Hide metadata objects
|
hideObject: false, // Hide metadata objects
|
||||||
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',
|
||||||
|
|
@ -149,10 +156,23 @@ export class Logger {
|
||||||
this.serviceName = serviceName;
|
this.serviceName = serviceName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a log level should be output based on global config
|
||||||
|
*/
|
||||||
|
private shouldLog(level: LogLevel): boolean {
|
||||||
|
const currentLevel = globalConfig.logLevel || 'info';
|
||||||
|
return LOG_LEVELS[level] >= LOG_LEVELS[currentLevel];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Core log method
|
* Core log method
|
||||||
*/
|
*/
|
||||||
private log(level: LogLevel, message: string | object, metadata?: LogMetadata): void {
|
private log(level: LogLevel, message: string | object, metadata?: LogMetadata): void {
|
||||||
|
// Skip if level is below current threshold
|
||||||
|
if (!this.shouldLog(level)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const data = { ...this.context, ...metadata };
|
const data = { ...this.context, ...metadata };
|
||||||
|
|
||||||
if (typeof message === 'string') {
|
if (typeof message === 'string') {
|
||||||
|
|
@ -321,30 +341,7 @@ export async function shutdownLoggers(): Promise<void> {
|
||||||
logger.info('Logger shutting down...');
|
logger.info('Logger shutting down...');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Flush all loggers
|
|
||||||
const flushPromises = Array.from(loggerCache.values()).map(logger => logger.flush());
|
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();
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// });
|
|
||||||
|
|
||||||
await Promise.all(flushPromises);
|
await Promise.all(flushPromises);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue