34 #include <uuid/common.h>
36 #ifndef UUID_COMMON_THREAD_SAFE
37 # define UUID_COMMON_THREAD_SAFE 0
40 #ifndef UUID_COMMON_STD_MUTEX_AVAILABLE
41 # define UUID_COMMON_STD_MUTEX_AVAILABLE 0
44 #if defined(DOXYGEN) || UUID_COMMON_STD_MUTEX_AVAILABLE
45 # define UUID_LOG_THREAD_SAFE 1
47 # define UUID_LOG_THREAD_SAFE 0
50 #if UUID_LOG_THREAD_SAFE
73 #if UUID_COMMON_THREAD_SAFE && UUID_LOG_THREAD_SAFE
149 std::vector<Level>
levels();
270 const __FlashStringHelper *
name;
325 virtual void operator<<(std::shared_ptr<Message> message) = 0;
467 void emerg(
const char *format, ...) const ;
475 void emerg(const __FlashStringHelper *format, ...) const ;
484 void alert(const
char *format, ...) const ;
492 void alert(const __FlashStringHelper *format, ...) const ;
501 void crit(const
char *format, ...) const ;
509 void crit(const __FlashStringHelper *format, ...) const ;
518 void err(const
char *format, ...) const ;
526 void err(const __FlashStringHelper *format, ...) const ;
535 void warning(const
char *format, ...) const ;
543 void warning(const __FlashStringHelper *format, ...) const ;
552 void notice(const
char *format, ...) const ;
560 void notice(const __FlashStringHelper *format, ...) const ;
569 void info(const
char *format, ...) const ;
576 void info(const __FlashStringHelper *format, ...) const ;
585 void debug(const
char *format, ...) const ;
593 void debug(const __FlashStringHelper *format, ...) const ;
602 void trace(const
char *format, ...) const ;
610 void trace(const __FlashStringHelper *format, ...) const ;
629 void log(
Level level, const __FlashStringHelper *format, ...) const ;
669 void vlog(
Level level, const __FlashStringHelper *format, va_list ap) const;
773 #if UUID_LOG_THREAD_SAFE
827 void loop(
size_t count = SIZE_MAX);
840 void operator<<(std::shared_ptr<Message> message)
override;
844 #if UUID_LOG_THREAD_SAFE
Logger handler used to process log messages.
friend Logger
Logger needs to be able to access the private reference to the registered log handlers.
virtual void operator<<(std::shared_ptr< Message > message)=0
Add a new log message.
std::weak_ptr< std::map< Handler *, Level > > handlers_
Reference to registered log handlers.
Logger instance used to make log messages.
bool enabled(Level level) const
Determine if the specified log level is enabled by the effective log level.
static void unregister_handler(Handler *handler)
Unregister a log handler.
void level(Level level)
Set the log level.
void notice(const char *format,...) const
Log a message at level Level::NOTICE.
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 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.
void vlog(Level level, const char *format, va_list ap) const
Log a message at the specified level.
Level level() const
Get the log level.
static Level global_level()
Get the current global log level.
void emerg(const char *format,...) const
Log a message at level Level::EMERG.
void info(const char *format,...) const
Log a message at level Level::INFO.
void err(const char *format,...) const
Log a message at level Level::ERR.
Level effective_level() const
Get the effective log level.
void logp(Level level, const char *text) const
Log a plain message (without formatting) at the specified level.
void alert(const char *format,...) const
Log a message at level Level::ALERT.
static std::atomic< Level > global_level_
static void register_handler(Handler *handler, Level level)
Register a log handler.
static constexpr size_t MAX_LOG_LENGTH
This is the maximum length of any log message.
Logger(const __FlashStringHelper *name, Facility facility=Facility::LOCAL0)
Create a new logger with the given name and logging facility.
void warning(const char *format,...) const
Log a message at level Level::WARNING.
void crit(const char *format,...) const
Log a message at level Level::CRIT.
static void refresh_log_level()
Refresh the minimum global log level across all handlers.
const __FlashStringHelper * name_
Facility facility() const
Get the default logging facility for new messages of this logger.
static std::shared_ptr< std::map< Handler *, Level > > & registered_handlers()
Get registered log handlers.
static Level get_log_level(const Handler *handler)
Get the current log level of a handler.
void trace(const char *format,...) const
Log a message at level Level::TRACE.
void debug(const char *format,...) const
Log a message at level Level::DEBUG.
void log(Level level, const char *format,...) const
Log a message with default facility.
Basic log handler for writing messages to any object supporting the Print interface.
void operator<<(std::shared_ptr< Message > message) override
Add a new log message.
void loop(size_t count=SIZE_MAX)
Dispatch queued log messages.
size_t maximum_log_messages() const
Get the maximum number of queued log messages.
size_t maximum_log_messages_
std::list< std::shared_ptr< Message > > log_messages_
static constexpr size_t MAX_LOG_MESSAGES
PrintHandler(Print &print)
Create a new Print log handler.
bool parse_level_lowercase(const std::string &name, Level &level)
Parse a lowercase string to a log level.
std::vector< std::string > levels_lowercase()
Get all log levels as lowercase strings.
Level
Severity level of log messages.
const __FlashStringHelper * format_level_lowercase(Level level)
Format a log level as a lowercase string.
std::vector< std::string > levels_uppercase()
Get all log levels as uppercase strings.
char format_level_char(Level level)
Format a log level as a single character.
std::string format_timestamp_ms(uint64_t timestamp_ms, unsigned int days_width)
Format a system uptime timestamp as a string.
std::vector< Level > levels()
Get all log levels.
static constexpr bool thread_safe
Thread-safe status of the library.
bool parse_level_uppercase(const std::string &name, Level &level)
Parse an uppercase string to a log level.
Facility
Facility type of the process logging a message.
const __FlashStringHelper * format_level_uppercase(Level level)
Format a log level as an uppercase string.
Log message text with timestamp and logger attributes.
const __FlashStringHelper * name
Name of the logger used (flash string).
const Level level
Severity level of the message.
const Facility facility
Facility type of the process that logged the message.
Message(uint64_t uptime_ms, Level level, Facility facility, const __FlashStringHelper *name, const std::string &&text)
Create a new log message (not directly useful).
const std::string text
Formatted log message text.
const uint64_t uptime_ms
System uptime at the time the message was logged.