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

Pad levels before label #352

Closed
Grigore147 opened this issue Jan 28, 2014 · 4 comments
Closed

Pad levels before label #352

Grigore147 opened this issue Jan 28, 2014 · 4 comments
Labels
Feature Request Request for new functionality to support use cases not already covered use a custom format

Comments

@Grigore147
Copy link

Hi there,

Pad level is now set for log message and when using labels we get:

info: [winston]    level info
verbose: [winston] level verbose
debug: [winston]   level debug
warn: [winston]    level error

by adding pad before label we will have:

info:    [winston] level info
verbose: [winston] level verbose
debug:   [winston] level debug
warn:    [winston] level error

or even pad log level only:

   info: [winston] level info
verbose: [winston] level verbose
  debug: [winston] level debug
   warn: [winston] level error

What do you think about this?
Thanks.

@mathieumg
Copy link

I would love the second option.

@mattcasey
Copy link

I prefer the second too (forgive me for just chiming in!) .. the third one would produce some very ragged lines on the left.

@mathieumg
Copy link

I attempted to write a PR to fix this, and unless I missed something it seems that a given Transport is completely unaware of the Logger that created it and that causes trouble. Since padLevels is specified as a Logger option, the way the padding is currently achieved feels hacky at best: when Logger.log() gets called, it modifies the message to prepend it with the amount of spaces required for padding before passing it to its Transports (who are the ones who know about their label). As soon as something gets placed after the logging level, but before the message (like a label...), this becomes less pretty. (See the first example above)

I will write a new PR with the following approach rather: Transport will have a levelPadLength option that Logger will pass off to all its Transports both initially and when a new one is added. For now, it would seem that levels can't change dynamically for a Logger, so this approach can't get "out of sync", but this is something to keep in mind if that were to change. Logger is the only one knowing about all used levels so it has to be the one informing each Transport.

The only thing that feels odd about all this is that when creating a Transport standalone the levelPadLength option feels out of place, but it still works well on its own (even if someone were to manually pick a number and only use one logging level). Unless there is another way for a Logger to transmit information to its Transports, I feel this is pretty much the only way to achieve this.

What are your thoughts?

@indexzero
Copy link
Member

In winston@3.0.0 you can implement this using a custom formats. Please consider upgrading.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Request Request for new functionality to support use cases not already covered use a custom format
Projects
None yet
Development

No branches or pull requests

4 participants