[libcamera-devel] [PATCH] libcamera: base: log: Use emoji's in log output

Laurent Pinchart laurent.pinchart at ideasonboard.com
Fri Apr 1 14:21:00 CEST 2022


(^_^)/ Kieran,

(^人^)

On Fri, Apr 01, 2022 at 10:03:09AM +0100, 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.

o_0 ... (^○^) !

> Signed-off-by: Kieran Bingham <kieran.bingham 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;
>  	}

-- 
Regards,

Laurent Pinchart


More information about the libcamera-devel mailing list