Reputation: 11890
Is there a way to log WARN and ERROR messages to the console using Vanilla JavaScript?
An example would be something that looks like:
I could just print it with console.log()
but it prints without color as just a plain message. I'd like to print it as an error or warning so it's colored output and background.
Most online guides suggest using some logger library such as log4javascript. I'm hoping to do this without pulling in any dependency.
Thanks!
Upvotes: 3
Views: 2510
Reputation: 486
You can use console.warn
and console.error
functions. First for warnings and second for errors.
https://developer.mozilla.org/es/docs/Web/API/Console/error https://developer.mozilla.org/es/docs/Web/API/Console/warn
Upvotes: 3
Reputation: 7189
console.warn('warning message');
Outputs a warning message to the Web Console.
https://developer.mozilla.org/en-US/docs/Web/API/Console/warn
console.error('error message');
Outputs an error message to the Web Console.
https://developer.mozilla.org/en-US/docs/Web/API/Console/error
Upvotes: 1