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

LevelName whitespace alignment issue #489

Closed
JohnPolansky opened this issue Jan 21, 2024 · 3 comments
Closed

LevelName whitespace alignment issue #489

JohnPolansky opened this issue Jan 21, 2024 · 3 comments

Comments

@JohnPolansky
Copy link

I'm using the following packages:

    "pino": "^8.17.2",
    "pino-pretty": "^10.3.1",

When I print out any messages using the colorize() option it appears that the message alignment is off
image

As you can see the INFO/WARN are throwing off messages which makes it a bit harder to read log messages. After searching various older posts I found a reference to this same issue back in 2021 that indicated this is an issue and it was fixed. Has something changed or am I missing a feature? #141

I also tried creating my own transport to padEnd() the log level, but this doesn't appear to work as below

import pino from 'pino-pretty'
import { colorizerFactory } from 'pino-pretty'
const levelColorize = colorizerFactory(true)
const levelPrettifier = logLevel => `${levelColorize(logLevel).padEnd(5)}`

export default (opts) => {
    return pino({
        ...opts,
        messageFormat: (log, messageKey) => `hello ${log[messageKey]}`
        customPrettifiers: {
            level: levelPrettifier
        }
    })
}

Here is my full logger.js for review:

import pino from 'pino';

//Create a logging instance
export const logger = pino({
  enabled: process.env.LOG_ENABLED === undefined ? true : process.env.LOG_ENABLED === 'true',
  transport: {
    // ...(process.env.LOG_PRETTY === true) && {'target': 'pino-pretty'},
    target: process.env.LOG_PRETTY === 'true' ? 'pino-pretty' : 'pino/file',
    // target: './pino-pretty-transport.js',
    options: {
      colorize: true,
      colorizeObjects: true,
      singleLine: true,
      ignore: 'pid,hostname',
    }
  },
  base: {},
  formatters: {
    level: (label) => {
      return { level: label };
    },
  },
  level: process.env.LOG_LEVEL || 'info',
  name: process.env.LOGGER_NAME,
  redact: {
    paths: ['token', 'password', 'uri'],
  },
  timestamp: pino.stdTimeFunctions.isoTime,
});

Thanks in advance for the help and the great tool.

@mcollina
Copy link
Member

Thanks for reporting. I don't exactly remember what happened.

@jsumners did you recall what happened on this one?

@jsumners
Copy link
Member

#140 is the last time this issue was discussed to the best of my recollection. In short, we've had two attempts performed at introducing the requested alignment. It seems it is not an easy feature to implement. I would rather not keep churning on the issue, but whomever feels strongly about it is welcome to work on it.

@FoxxMD
Copy link
Contributor

FoxxMD commented Mar 20, 2024

@JohnPolansky in pino-pretty v11.0.0 you now have access to the log level label and alignment in now possible. An example from my PR:

{
  customPrettifiers: {
        level: (logLevel, key, log, { label, labelColorized }) => {
            // pad to fix alignment
            // assuming longest level is 5 characters long
            // and may be colorized
            const paddedLabel = label.padEnd(5)
            if(labelColorized !== label) {
                const padDiff = paddedLabel.length - label.length;
                return labelColorized.padEnd(labelColorized.length + padDiff);
            }
            return paddedLabel;
        }
    },
}

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

4 participants