Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Dev-Paxton opened this issue Oct 8, 2023 · 0 comments

Comments

@Dev-Paxton
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant