[libcamera-devel] [PATCH] libcamera: base: log: Use emoji's in log output
Umang Jain
umang.jain at ideasonboard.com
Fri Apr 1 15:51:28 CEST 2022
Hello,
That's a perfect patch for friday :-D
On 4/1/22 14:33, Kieran Bingham via libcamera-devel wrote:
> Our debug logs are already growing terse and difficult to parse with the
> eye. The specific notifications can easily blend into each other.
>
> Add some highlight and colour to the log messages by replacing
> the log severity levels with emoji characters which convey
> the same meaning but in much less space.
>
> Syslog and output to files remains unchanged. Only stream outputs
> display emoji symbols.
>
> Signed-off-by: Kieran Bingham <kieran.bingham at ideasonboard.com>
Nice to have surely,
Reviewed-by: Umang Jain <umang.jain at ideasonboard.com>
> ---
> src/libcamera/base/log.cpp | 25 ++++++++++++++++++++++++-
> 1 file changed, 24 insertions(+), 1 deletion(-)
>
> diff --git a/src/libcamera/base/log.cpp b/src/libcamera/base/log.cpp
> index 64813b6607c5..aceec7302549 100644
> --- a/src/libcamera/base/log.cpp
> +++ b/src/libcamera/base/log.cpp
> @@ -96,6 +96,23 @@ static const char *log_severity_name(LogSeverity severity)
> return "UNKWN";
> }
>
> +static const std::string &log_severity_emojis(LogSeverity severity)
> +{
> + static const std::string emojis[] = {
> + "🪲 ", // DEBUG
> + "ℹ️ ", // INFO
> + "⚠️ ", // WARNING
> + "🔥 ", // ERROR
> + "🆘 ", // FATAL
> + "🤔 ", // Unknown
> + };
> +
> + if (static_cast<unsigned int>(severity) < std::size(emojis))
> + return emojis[severity];
> + else
> + return emojis[std::size(emojis) - 1];
> +}
> +
> /**
> * \brief Log output
> *
> @@ -194,7 +211,6 @@ void LogOutput::write(const LogMessage &msg)
> + msg.msg();
> writeSyslog(msg.severity(), str);
> break;
> - case LoggingTargetStream:
> case LoggingTargetFile:
> str = "[" + utils::time_point_to_string(msg.timestamp()) + "] ["
> + std::to_string(Thread::currentId()) + "] "
> @@ -203,6 +219,13 @@ void LogOutput::write(const LogMessage &msg)
> + msg.msg();
> writeStream(str);
> break;
> + case LoggingTargetStream:
> + str = "[" + utils::time_point_to_string(msg.timestamp()) + "] ["
> + + std::to_string(Thread::currentId()) + "] "
> + + log_severity_emojis(msg.severity()) + " "
> + + msg.category().name() + " " + msg.fileInfo() + " "
> + + msg.msg();
> + writeStream(str);
> default:
> break;
> }
More information about the libcamera-devel
mailing list