Skip to content

Commit

Permalink
fix: allows log message args as well as metadata
Browse files Browse the repository at this point in the history
Signed-off-by: Lenin Mehedy <lenin.mehedy@swirldslabs.com>
  • Loading branch information
leninmehedy committed Oct 26, 2023
1 parent d083766 commit 2fde80b
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions fullstack-network-manager/src/core/logging.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as winston from 'winston'
import {constants} from "./constants.mjs";
import { v4 as uuidv4 } from 'uuid';
import {v4 as uuidv4} from 'uuid';
import * as util from "util";

const customFormat = winston.format.combine(
Expand Down Expand Up @@ -80,7 +80,7 @@ const Logger = class {
this.traceId = uuidv4()
}

enrichMeta(meta) {
prepMeta(meta) {
if (meta === undefined) {
meta = {}
}
Expand All @@ -93,31 +93,31 @@ const Logger = class {
console.log(util.format(msg, ...args))
}

critical(msg, ...meta) {
this.winsonLogger.crit(msg, this.enrichMeta(meta))
critical(msg, ...args) {
this.winsonLogger.crit(msg, ...args, this.prepMeta())
}

error(msg, ...meta) {
this.winsonLogger.error(msg, this.enrichMeta(meta))
error(msg, ...args) {
this.winsonLogger.error(msg, ...args, this.prepMeta())
}

warn(msg, ...meta) {
this.winsonLogger.warn(msg, this.enrichMeta(meta))
warn(msg, ...args) {
this.winsonLogger.warn(msg, ...args, this.prepMeta())
}

notice(msg, ...meta) {
this.winsonLogger.notice(msg, this.enrichMeta(meta))
notice(msg, ...args) {
this.winsonLogger.notice(msg, ...args, this.prepMeta())
}

info(msg, ...meta) {
this.winsonLogger.info(msg, this.enrichMeta(meta))
info(msg, ...args) {
this.winsonLogger.info(msg, ...args, this.prepMeta())
}

debug(msg, ...meta) {
this.winsonLogger.debug(msg, this.enrichMeta(meta))
debug(msg, ...args) {
this.winsonLogger.debug(msg, ...args, this.prepMeta())
}
}

export function NewLogger(level = 'debug') {
export function NewLogger(level = 'debug') {
return new Logger(level)
}

0 comments on commit 2fde80b

Please sign in to comment.