-
Notifications
You must be signed in to change notification settings - Fork 11
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
Optional color configuration for custom log levels #3
base: master
Are you sure you want to change the base?
Conversation
import DiscordTransport from 'winston-discord-transport'; | ||
|
||
const levelColors = { | ||
emerg: 9315107, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do emerg
and some of these other levels exist in winston?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, so how is it propagated to the transports?
Should the transport check for both kind of levels? Or does winston propagate the level
to the transports in the default way (i.e. error, warn, info, etc in that order)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The level is sent to the transport as info.level
, for example:
{
message: 'An example log',
level: 'notice',
service: 'example-service',
timestamp: '2021-03-29 12:28:30',
[Symbol(level)]: 'notice',
[Symbol(message)]: '{"message":"An example log","level":"notice","service":"example-service","timestamp":"2021-03-29 12:28:30"}'
}
There doesn't seem to be any way of getting the full log level/color configuration from winston. winstonjs/winston#1425
Perhaps a better approach would be to update the Colors
interface to use the same type signature as Winston's AbstractConfigSetColors
:
interface Colors {
[key: string]: string | string[];
}
This would allow you to configure the transport using the built-in level configurations like this:
new DiscordTransport({
webhook: 'https:/your/discord/webhook',
defaultMeta: { service: 'my_node_service' },
level: 'notice',
colors: winston.config.syslog.colors
})
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice idea!
Although, I was working on moving this functionality to a standalone discord logger - https://github.com/sidhantpanda/node-discord-logger
And working to use that library inside this transport - https://github.com/sidhantpanda/winston-discord-transport/blob/feat/use_external_node_discord_lib/src/index.ts under branch eat/use_external_node_discord_lib
.
I can create this feature in that library and extend those options here and add you as collaborator in the README. I don't want to discard your efforts here :(
Or if you feel like it, you can create this pull request there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, node-discord-logger
looks great! I really like the error/json logging and the customizable metadata per log!
Would you plan then to extend node-discord-logger
to allow configuration of custom logging/levels and colours?
I think that after migrating to use node-discord-logger
in the transport it would be useful to accept some configuration in the form of winston's AbstractConfigSet
and pass to node-discord-logger
to configure both logging levels and colors. What do you think?
More than happy to help out with either library if you'd like.
Big fan of this library, thanks for writing it!
This is a small PR to add an optional
color
parameter containing a map of log levels to colors to theDiscordTransportOptions
. When set, this will override the default color map.