Hello,
I was wondering if it was possible to add a custom log level to add granularity to my personal logs.
In the LogLevel enum in the logging.h header we have the following:
// Log level. Ensure log_level_name() is updated for newly added levels
typedef enum LogLevel {
LOG_LEVEL_ALL = 1, // Log all messages
LOG_LEVEL_TRACE = 1,
LOG_LEVEL_INFO = 30,
LOG_LEVEL_WARN = 40,
LOG_LEVEL_ERROR = 50,
LOG_LEVEL_PANIC = 60,
LOG_LEVEL_NONE = 70, // Do not log any messages
// Compatibility levels
DEFAULT_LEVEL = 0,
ALL_LEVEL = LOG_LEVEL_ALL,
TRACE_LEVEL = LOG_LEVEL_TRACE,
LOG_LEVEL = LOG_LEVEL_TRACE, // Deprecated
DEBUG_LEVEL = LOG_LEVEL_TRACE, // Deprecated
INFO_LEVEL = LOG_LEVEL_INFO,
WARN_LEVEL = LOG_LEVEL_WARN,
ERROR_LEVEL = LOG_LEVEL_ERROR,
PANIC_LEVEL = LOG_LEVEL_PANIC,
NO_LOG_LEVEL = LOG_LEVEL_NONE
} LogLevel;
So I was wondering if it would be possible to “register” another level, say something like LOG_LEVEL_TRACE_2 with the value 2, LOG_LEVEL_TRACE_3 with value 3, etc… From what little I could discern, it seemed as though the LogLevel enum couldn’t really be extended except by Particle since there’s a function log_level_name() that goes with this. I’ve tried looking into the implementation details for the logging but I wasn’t really sure where to start. Would this require subclassing an existing log handler, say SerialLogHandler for example?
Any help and suggestions are greatly appreciated.
Thank you.