small log fixes
This commit is contained in:
parent
62a29259b9
commit
afa381e390
4 changed files with 32 additions and 26 deletions
|
|
@ -9,14 +9,14 @@
|
|||
*/
|
||||
|
||||
import pino from 'pino';
|
||||
import type { LogContext, LogLevel, LogMetadata, LoggerConfig } from './types';
|
||||
import type { LogContext, LoggerConfig, LogLevel, LogMetadata } from './types';
|
||||
|
||||
// Simple cache for logger instances
|
||||
const loggerCache = new Map<string, pino.Logger>();
|
||||
|
||||
// Global config that can be set
|
||||
let globalConfig: LoggerConfig = {
|
||||
logLevel: 'info', // Default to info, but trace and fatal are supported
|
||||
logLevel: 'info', // Default to info, but trace and fatal are supported
|
||||
logConsole: true,
|
||||
logFile: false,
|
||||
logFilePath: './logs',
|
||||
|
|
@ -39,7 +39,7 @@ export function setLoggerConfig(config: LoggerConfig): void {
|
|||
*/
|
||||
function createTransports(serviceName: string, config: LoggerConfig = globalConfig): any {
|
||||
const targets: any[] = [];
|
||||
|
||||
|
||||
// Console transport
|
||||
if (config.logConsole) {
|
||||
targets.push({
|
||||
|
|
@ -82,12 +82,14 @@ function createTransports(serviceName: string, config: LoggerConfig = globalConf
|
|||
environment: config.environment || 'development',
|
||||
},
|
||||
ignore: 'childName',
|
||||
...(config.lokiUser && config.lokiPassword ? {
|
||||
basicAuth: {
|
||||
username: config.lokiUser,
|
||||
password: config.lokiPassword,
|
||||
},
|
||||
} : {}),
|
||||
...(config.lokiUser && config.lokiPassword
|
||||
? {
|
||||
basicAuth: {
|
||||
username: config.lokiUser,
|
||||
password: config.lokiPassword,
|
||||
},
|
||||
}
|
||||
: {}),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
@ -294,7 +296,11 @@ export class Logger {
|
|||
/**
|
||||
* Main factory function
|
||||
*/
|
||||
export function getLogger(serviceName: string, context?: LogContext, config?: LoggerConfig): Logger {
|
||||
export function getLogger(
|
||||
serviceName: string,
|
||||
context?: LogContext,
|
||||
config?: LoggerConfig
|
||||
): Logger {
|
||||
return new Logger(serviceName, context, config);
|
||||
}
|
||||
|
||||
|
|
@ -321,8 +327,8 @@ export async function shutdownLoggers(): Promise<void> {
|
|||
|
||||
try {
|
||||
await Promise.allSettled(flushPromises);
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('All loggers flushed successfully');
|
||||
|
||||
// console.log('All loggers flushed successfully');
|
||||
} catch (error) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error('Logger flush failed:', error);
|
||||
|
|
@ -332,4 +338,4 @@ export async function shutdownLoggers(): Promise<void> {
|
|||
}
|
||||
|
||||
// Export types for convenience
|
||||
export type { LogLevel, LogContext, LogMetadata } from './types';
|
||||
export type { LogContext, LogLevel, LogMetadata } from './types';
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue