[libcamera-devel] libcamera: base: log: Use emoji's in log output
diff mbox series

Message ID 20220401090309.2704921-1-kieran.bingham@ideasonboard.com
State RFC
Headers show
Series
  • [libcamera-devel] libcamera: base: log: Use emoji's in log output
Related show

Commit Message

Kieran Bingham April 1, 2022, 9:03 a.m. UTC
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@ideasonboard.com>
---
 src/libcamera/base/log.cpp | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)

Comments

Laurent Pinchart April 1, 2022, 12:21 p.m. UTC | #1
(^_^)/ 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@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;
>  	}
Umang Jain April 1, 2022, 1:51 p.m. UTC | #2
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@ideasonboard.com>


Nice to have surely,

Reviewed-by: Umang Jain <umang.jain@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;
>   	}

Patch
diff mbox series

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;
 	}