winstonjs/logform

[Bug]: Strange behavior from the info object given to printf from createLogger()

Dev-Paxton opened this issue · 0 comments

The problem

See below

What version of Logform presents the issue?

v2.5.1

What version of Node are you using?

v18.18.0

If this is a TypeScript issue, what version of TypeScript are you using?

v5.2.2

If this worked in a previous version of Logform, which was it?

No response

Minimum Working Example

import winston, { format } from "winston"

const customFormat = format.printf(info => {
    console.log(info)

    if (typeof info ===  "object") info.message = JSON.stringify(info.message, null, 4)
    
    let head = `${timeFormat()} ${info.level}: `

    let space = ""
    while (head.length + space.length < 45){
        space = space + " "
    }
    return head + space + info.message
})

function timeFormat() {
    const date = new Date()
    return `[${date.getDate().toString().padStart(2, "0")}.${(date.getMonth() + 1).toString().padStart(2, "0")}.${date.getFullYear()} ${date.getHours().toString().padStart(2, "0")}:${date.getMinutes().toString().padStart(2, "0")}:${date.getSeconds().toString().padStart(2, "0")}]`
}

const loggerFormat = format.combine(format.colorize(), customFormat)

export const logger = winston.createLogger({
    level: "silly",
    format: loggerFormat,
    transports: [
        new winston.transports.Console({
            level: "debug"
        })
    ]
})

logger.debug({type: "Test", error: "Test"})
logger.debug({type: "Test", message: "Test"})

Additional information

Output:

{
  message: { type: 'Test', error: 'Test' },
  level: '\x1B[34mdebug\x1B[39m',
  [Symbol(level)]: 'debug'
}
[08.10.2023 17:49:57] debug:       {
    "type": "Test",
    "error": "Test"
}
{
  type: 'Test',
  message: 'Test',
  level: '\x1B[34mdebug\x1B[39m',
  [Symbol(level)]: 'debug'
}
[08.10.2023 17:49:57] debug:       "Test"

Expected Output:

{
  message: { type: 'Test', error: 'Test' },
  level: '\x1B[34mdebug\x1B[39m',
  [Symbol(level)]: 'debug'
}
[08.10.2023 17:49:57] debug:       {
    "type": "Test",
    "error": "Test"
}
{
  message: { type: 'Test', message: 'Test' },
  level: '\x1B[34mdebug\x1B[39m',
  [Symbol(level)]: 'debug'
}
[08.10.2023 17:49:57] debug:       {
    "type": "Test",
    "error": "Test"
}

🔎 Search Terms

format