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

log: force red color on errors, yellow on warnings. #860

Merged
merged 3 commits into from
Nov 2, 2016
Merged

Conversation

paulirish
Copy link
Member

Small followup from #835, from @wardpeet's suggestion..

Errors are red, warnings are yellow. And the other logs will never use those colors

image
image

static loggerfn(title) {
let log = loggersByTitle[title];
if (!log) {
log = loggersByTitle[title] = debug(title);
Copy link
Contributor

Choose a reason for hiding this comment

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

two lines for rock solid clarity

Copy link
Member Author

Choose a reason for hiding this comment

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

done

const EventEmitter = require('events').EventEmitter;

debugNode.colors = [6, 2, 4, 5];
Copy link
Contributor

Choose a reason for hiding this comment

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

can you add a comment for what these does. I'm a noob.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

log = loggersByTitle[title] = debug(title);
// errors with red, warnings with yellow.
// eslint-disable-next-line no-nested-ternary
log.color = title.includes('error') ? 1 : title.includes('warn') ? 3 : undefined;
Copy link
Contributor

Choose a reason for hiding this comment

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

1/3 could be enums

Copy link
Member Author

Choose a reason for hiding this comment

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

done

if (!loggersByTitle[title]) {
loggersByTitle[title] = debug(title);
const log = Log.loggerfn(title);
return log(...args);
Copy link
Member

Choose a reason for hiding this comment

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

what do these return, incidentally?

Copy link
Member Author

Choose a reason for hiding this comment

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

undefined. i'll nuke the explicit return

loggersByTitle[title] = log;
// errors with red, warnings with yellow.
// eslint-disable-next-line no-nested-ternary
log.color = title.endsWith('error') ? colors.red :
Copy link
Contributor

Choose a reason for hiding this comment

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

nit extract this lookup logic into a named fn.

nit extract error and warn string into named module private consts

Copy link
Member

Choose a reason for hiding this comment

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

nit extract error and warn string into named module private consts

disagree (maybe if we were exposing Log.ERROR but we have log.error() for that), but that shouldn't be a surprise by this point :)

Copy link
Member

@brendankenny brendankenny left a comment

Choose a reason for hiding this comment

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

LGTM

@paulirish paulirish merged commit d7f5226 into master Nov 2, 2016
@paulirish paulirish deleted the logrederrors branch November 6, 2016 03:33
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.

4 participants