[libcamera-devel] [PATCH] libcamera: log: add colors to log levels

Jean-Michel Hautbois jeanmichel.hautbois at ideasonboard.com
Wed Feb 3 20:26:51 CET 2021


Hi Marien,

Thanks for the patch !

On 03/02/2021 20:13, Marian Cichy wrote:
> Hi Sebastian,
> 
> thanks, I also just realized that I probably should sign-off, right?
> 
> should I send a V2?
> 
> regards,
> 
> marian
> 
> On 2/3/21 8:09 PM, Sebastian Fricke wrote:
>> Hey Marian,
>>
>> Thank you for the patch.
>> This looks better than before, I tested it on my machine and it worked
>> without problems.
>> If you like to you can add:
>> Tested-by: Sebastian Fricke <sebastian.fricke at posteo.net>
>>
>> Greetings,
>> Sebastian
>>
>> On 03.02.2021 19:17, Marian Cichy wrote:
>>> mono-colored wall of logs can be hard to read and doesn't show the level
>>> of failure at a first glance. By adding colors to the log level
>>> categories, it is much easier to scroll through logs and find important
>>> entries.
>>> ---
>>> src/libcamera/log.cpp | 10 +++++-----
>>> 1 file changed, 5 insertions(+), 5 deletions(-)
>>>
>>> diff --git a/src/libcamera/log.cpp b/src/libcamera/log.cpp
>>> index 45c7c2d2..3ad9c3de 100644
>>> --- a/src/libcamera/log.cpp
>>> +++ b/src/libcamera/log.cpp
>>> @@ -85,11 +85,11 @@ static int log_severity_to_syslog(LogSeverity
>>> severity)
>>> static const char *log_severity_name(LogSeverity severity)
>>> {
>>>     static const char *const names[] = {
>>> -        "DEBUG",
>>> -        " INFO",
>>> -        " WARN",
>>> -        "ERROR",
>>> -        "FATAL",
>>> +        "\033[1m\033[37mDEBUG\033[0m",
>>> +        "\033[1m\033[32m INFO\033[0m",
>>> +        "\033[1m\033[33m WARN\033[0m",
>>> +        "\033[1m\033[31mERROR\033[0m",
>>> +        "\033[1m\033[35mFATAL\033[0m",
>>>     };

I like the idea, but I would prefer having the possibility to
enable/disable it at runtime, as for copy/pasting debug logs it is
easier to read uncolored :-).

JM


More information about the libcamera-devel mailing list