8000 feat(console.js): use native console.error for ERROR level logs and higher by feyy · Pull Request #349 · log4js-node/log4js-node · GitHub
[go: up one dir, main page]

Skip to content

feat(console.js): use native console.error for ERROR level logs and higher #349

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

Closed
wants to merge 1 commit into from

Conversation

feyy
Copy link
@feyy feyy commented Feb 1, 2016

Only using console.log and color to distinguish levels isn't appropriate, especially when using with 'pm2'. The error logs will be writted in normal 'out' logs.

@nomiddlename
Copy link
Collaborator

Thanks for this. Does pm2 require your error logs to go to stderr? It sounds like you want to override the native console.* methods to get log4js style formatting, but you want error (and above) level messages to go to standard error instead of standard out - is this correct? There may be a better way to do that - I'm not sure that everyone who uses log4js will want the same thing. Perhaps we need a way to specify stdout and stderr as appenders separately, instead of just one "console" appender. What are your thoughts?

@feyy
Copy link
Author
feyy commented Feb 2, 2016

Yes. I just want the error logs to go to standard error, your scheme is more suitable. Looking forward to your next release.

@MichielDeMey
Copy link

I agree, we're currently using supervisord to monitor our logs and all logging levels appear in the stdout logs instead of actual errors going into the stderr logs.


function consoleAppender (layout, timezoneOffset) {
layout = layout || layouts.colouredLayout;
return function(loggingEvent) {
consoleLog(layout(loggingEvent, timezoneOffset));
if (loggingEvent.level.level >= levels.ERROR.level) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the node documentation, warnings are also logged to stderr since it's just an alias for console.error.
https://nodejs.org/api/console.html#console_console_warn_data

@nomiddlename
Copy link
Collaborator

Does pull request #364 solve your problem?

@MichielDeMey
Copy link

It does, but it feels weird that in order to print to stderr you would need the stderrAppender but to write to stdout you would need the consoleAppender.

Feels like we should at least provide an alias stdoutAppender that aliases to consoleAppender.

Any thoughts around this?

@nomiddlename
Copy link
Collaborator

Closing this because there are now stdout and stderr appenders.

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

Successfully merging this pull request may close these issues.

3 participants
0