-
Notifications
You must be signed in to change notification settings - Fork 517
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
Question: How to create custom Levels? #228
Comments
Currently, no easily. While the 'level' is a number to theoretically allow using values other than the named ones... the code currently makes that difficult. The std set of level names are hardcoded in various vars in both bunyan.js and the To start, what you'd want is something like how the std levels are added to the Logger class:
But the |
Precisely where I was at before finding this issue... :) How about having a generic log emitter which would take the level as the first parameter (like Winston has)? |
I needed a 'notice' level between info and warn; this is what I came up with: #300 |
Awesome! Thanks a bunch :) Essentially I'll use this to clear out the clutter. So I can see only the messages that I want to see :) |
If anyone finds this via Google like I did, here's our workaround |
const bunyan = require('bunyan')
bunyan.levelFromName['info_extended'] = 35
bunyan.nameFromLevel[35] = 'info_extended'
bunyan.INFO_EXTENDED = 35
bunyan.prototype.infoEx = function infoExtended () {
const customLogLevel = 35
if (typeof arguments[0] === 'string') {
this.info.apply(this, { level: customLogLevel }, arguments)
}
if (typeof arguments[0] === 'object') {
arguments[0].level = customLogLevel
this.info.apply(this, arguments)
}
} |
Just curious to how I can create a custom level name and level value?
This way I can have more useful log files.
example idea {level: 'loginError', value:51, msg: 'etc'}
The text was updated successfully, but these errors were encountered: