better logger
This commit is contained in:
@@ -24,10 +24,13 @@ type WarnLogParams = LogParams & { err?: Error };
|
||||
|
||||
class CustomLogger implements Logger {
|
||||
trace({ message, args }: LogParams) {
|
||||
logger.info(message, args);
|
||||
logger.debug(message, args);
|
||||
}
|
||||
debug({ message, args }: LogParams) {
|
||||
logger.info(message, args);
|
||||
if (message.includes('Query:') && args?.response_status === 200) {
|
||||
return;
|
||||
}
|
||||
logger.debug(message, args);
|
||||
}
|
||||
info({ message, args }: LogParams) {
|
||||
logger.info(message, args);
|
||||
|
||||
@@ -67,13 +67,9 @@ export function createLogger({ name }: { name: string }): ILogger {
|
||||
return Object.assign({}, info, redactObject(info));
|
||||
});
|
||||
|
||||
const format = winston.format.combine(
|
||||
errorFormatter(),
|
||||
redactSensitiveInfo(),
|
||||
winston.format.json(),
|
||||
);
|
||||
const transports: winston.transport[] = [];
|
||||
let format: winston.Logform.Format;
|
||||
|
||||
const transports: winston.transport[] = [new winston.transports.Console()];
|
||||
if (process.env.HYPERDX_API_KEY) {
|
||||
transports.push(
|
||||
HyperDX.getWinstonTransport(logLevel, {
|
||||
@@ -81,6 +77,24 @@ export function createLogger({ name }: { name: string }): ILogger {
|
||||
service,
|
||||
}),
|
||||
);
|
||||
format = winston.format.combine(
|
||||
errorFormatter(),
|
||||
redactSensitiveInfo(),
|
||||
winston.format.json(),
|
||||
);
|
||||
} else {
|
||||
transports.push(new winston.transports.Console());
|
||||
format = winston.format.combine(
|
||||
errorFormatter(),
|
||||
redactSensitiveInfo(),
|
||||
winston.format.colorize(),
|
||||
winston.format.printf((info) => {
|
||||
const { level, message, service, ...meta } = info;
|
||||
const metaStr =
|
||||
Object.keys(meta).length > 0 ? ` ${JSON.stringify(meta)}` : '';
|
||||
return `${level} ${message}${metaStr}`;
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
const logger = winston.createLogger({
|
||||
|
||||
Reference in New Issue
Block a user