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

Logger: out of box color support for errors and warnings #11215

Open
snitin315 opened this issue Jul 21, 2020 · 14 comments
Open

Logger: out of box color support for errors and warnings #11215

snitin315 opened this issue Jul 21, 2020 · 14 comments

Comments

@snitin315
Copy link
Member

Feature request

Logger should support colors for errors and warnings out of the box.

What is the expected behavior?
if we log warning with logger.warn('warning') it should print the warning in yellow color. same for errors with red colors.

What is motivation or use case for adding/changing the behavior?
we have use color ourself like logger.warn(chalk.yellow('warning'))

How should this be implemented in your opinion?

Are you willing to work on this yourself?
yes

@sokra
Copy link
Member

sokra commented Jul 23, 2020

image

It does already do that

@snitin315
Copy link
Member Author

const logging = require('webpack/lib/logging/runtime');

logging.getLogger('test').info('helllo');

The above code outputs without color, do we have to specify some other configurations to get the colors?
Screenshot at 2020-07-29 16-08-38

@alexander-akait
Copy link
Member

@snitin315 strange, can you try to use warning/error?

@snitin315
Copy link
Member Author

Same behavior.
Screenshot at 2020-07-29 17-59-46

@sokra
Copy link
Member

sokra commented Jul 29, 2020

This is not how to use the webpack logger. Use compilation.getLogger("my-plugin")

@snitin315
Copy link
Member Author

we use logging before we run webpack and sometimes after, and when we do other actions that don't need webpack (like init/info/migrate/generate), so I think we can't use infrastructure logger.

@alexander-akait
Copy link
Member

@snitin315 we need to search way how we can implement colors using built-in logger

@snitin315
Copy link
Member Author

@sokra isn't it possible to have colors with runtime?

@alexander-akait
Copy link
Member

@snitin315 Please check the code, it is easy

@sokra
Copy link
Member

sokra commented Jul 31, 2020

The runtime logger is intended for in browser usage where the browser devtools take care of colors and filtering.

It's not intended for usage in node.js, because you won't have the ability to filter.

It probably makes sense to offer multiple different runtime loggers for web and node.js targets. A node.js logger could apply console colors and filter e. g. via env variable.

webpack would alias the logger depending on target.

As side effect you would be able to use the node.js runtime logger for your stuff too.

@snitin315
Copy link
Member Author

@sokra makes sense, How should I go ahead in Implementing this feature?

@webpack-bot
Copy link
Contributor

This issue had no activity for at least three months.

It's subject to automatic issue closing if there is no activity in the next 15 days.

@snitin315
Copy link
Member Author

Bump

@webpack-bot
Copy link
Contributor

Issue was closed because of inactivity.

If you think this is still a valid issue, please file a new issue with additional information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants