rui.melo's avatar

Adding colors to Log Facade

Is there an easy way to set colors for the Log Facade console and file output?

Everything I've searched is overly complicated in terms of registering a new facade with a service provider just for this or bootstrapping the logging system for each channel I wan't to affect.

I just want to call Log::error('some error') and get a red message on my console and log files.

Currently I've been using a color class for this but it has been a bit daunting to always define it every time a need to set a new color for the output.

Log::warning(Color::paint('error message', 'yellow'));
Log::error(Color::paint('error message', 'red'));
0 likes
2 replies
Cronix's avatar

Why don't you just make your own Log class that just proxies to those, so when you do YourLog::warning($text) it just returns Log::warning(Color::paint($text, 'yellow'));

Not everybody is using logging output on the CLI. Most are logging to files/services where color is irrelevant and it's the log type that counts (warning/error/info/etc).

rui.melo's avatar

@cronix I was trying to avoid a workaround but it'll have to work for now. Thank you

Please or to participate in this conversation.