29 #if UUID_LOG_THREAD_SAFE
41 #if UUID_LOG_THREAD_SAFE
47 if (level < Level::EMERG) {
49 }
else if (level > Level::TRACE) {
57 : uptime_ms(uptime_ms), level(level), facility(facility), name(name), text(std::move(text)) {
61 : name_(name), facility_(facility) {
66 static std::shared_ptr<std::map<Handler*,Level>> handlers = std::make_shared<std::map<Handler*,Level>>();
72 #if UUID_LOG_THREAD_SAFE
73 std::lock_guard<std::mutex> lock{
mutex_};
78 (*handlers)[handler] =
level;
83 auto handlers = handler->
handlers_.lock();
86 #if UUID_LOG_THREAD_SAFE
87 std::lock_guard<std::mutex> lock{
mutex_};
90 if (handlers->erase(handler)) {
97 #if UUID_LOG_THREAD_SAFE
98 std::lock_guard<std::mutex> lock{
mutex_};
102 const auto level = handlers->find(
const_cast<Handler*
>(handler));
104 if (
level != handlers->end()) {
105 return level->second;
115 va_start(ap, format);
125 va_start(ap, format);
135 va_start(ap, format);
145 va_start(ap, format);
155 va_start(ap, format);
165 va_start(ap, format);
174 va_start(ap, format);
184 va_start(ap, format);
194 va_start(ap, format);
204 va_start(ap, format);
214 va_start(ap, format);
224 va_start(ap, format);
234 va_start(ap, format);
244 va_start(ap, format);
254 va_start(ap, format);
264 va_start(ap, format);
274 va_start(ap, format);
284 va_start(ap, format);
296 va_start(ap, format);
308 va_start(ap, format);
320 va_start(ap, format);
332 va_start(ap, format);
373 if (vsnprintf(text.data(), text.size(), format, ap) <= 0) {
383 if (vsnprintf_P(text.data(), text.size(),
reinterpret_cast<PGM_P
>(format), ap) <= 0) {
406 text.shrink_to_fit();
411 #if UUID_LOG_THREAD_SAFE
412 std::lock_guard<std::mutex> lock{
mutex_};
416 if (message->level <= handler.second) {
417 *handler.first << message;
427 if (
level < handler.second) {
428 level = handler.second;
std::weak_ptr< std::map< Handler *, Level > > handlers_
Reference to registered log handlers.
void err(const char *format,...) const
Log a message at level Level::ERR.
uint64_t get_uptime_ms()
Get the current uptime as a 64-bit milliseconds value.
void notice(const char *format,...) const
Log a message at level Level::NOTICE.
const __FlashStringHelper * name_
void trace(const char *format,...) const
Log a message at level Level::TRACE.
Facility
Facility type of the process logging a message.
void dispatch(Level level, Facility facility, std::vector< char > &text) const
Dispatch a log message to all handlers that are registered to handle messages of the specified level.
Logger(const __FlashStringHelper *name, Facility facility=Facility::LOCAL0)
Create a new logger with the given name and logging facility.
void info(const char *format,...) const
Log a message at level Level::INFO.
Level level() const
Get the log level.
Message(uint64_t uptime_ms, Level level, Facility facility, const __FlashStringHelper *name, const std::string &&text)
Create a new log message (not directly useful).
Level
Severity level of log messages.
static void refresh_log_level()
Refresh the minimum global log level across all handlers.
void logp(Level level, const char *text) const
Log a plain message (without formatting) at the specified level.
Logger handler used to process log messages.
static void register_handler(Handler *handler, Level level)
Register a log handler.
Facility facility() const
Get the default logging facility for new messages of this logger.
void debug(const char *format,...) const
Log a message at level Level::DEBUG.
static Level get_log_level(const Handler *handler)
Get the current log level of a handler.
static std::atomic< Level > global_level_
void vlog(Level level, const char *format, va_list ap) const
Log a message at the specified level.
static void unregister_handler(Handler *handler)
Unregister a log handler.
void log(Level level, const char *format,...) const
Log a message with default facility.
bool enabled(Level level) const
Determine if the specified log level is enabled by the effective log level.
void warning(const char *format,...) const
Log a message at level Level::WARNING.
static constexpr size_t MAX_LOG_LENGTH
This is the maximum length of any log message.
void vlog_internal(Level level, Facility facility, const char *format, va_list ap) const
Log a message at the specified level and facility without checking that the specified level is enable...
void emerg(const char *format,...) const
Log a message at level Level::EMERG.
void alert(const char *format,...) const
Log a message at level Level::ALERT.
void crit(const char *format,...) const
Log a message at level Level::CRIT.
static std::shared_ptr< std::map< Handler *, Level > > & registered_handlers()
Get registered log handlers.