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
const Level level
Severity level of the message.
Logger instance used to make log messages.
Basic log handler for writing messages to any object supporting the Print interface.
std::weak_ptr< std::map< Handler *, Level > > handlers_
Reference to registered log handlers.
const __FlashStringHelper * format_level_lowercase(Level level)
Format a log level as a lowercase string.
void err(const char *format,...) const
Log a message at level Level::ERR.
Log message text with timestamp and logger attributes.
Level effective_level() const
Get the effective log level.
PrintHandler(Print &print)
Create a new Print log handler.
const __FlashStringHelper * format_level_uppercase(Level level)
Format a log level as an uppercase string.
void loop(size_t count=SIZE_MAX)
Dispatch queued log messages.
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.
std::vector< std::string > levels_lowercase()
Get all log levels as lowercase strings.
static constexpr size_t MAX_LOG_MESSAGES
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.
const __FlashStringHelper * name
Name of the logger used (flash string).
size_t maximum_log_messages_
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.
std::vector< Level > levels()
Get all log levels.
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.
size_t maximum_log_messages() const
Get the maximum number of queued log messages.
static Level global_level()
Get the current global log level.
static std::atomic< Level > global_level_
const Facility facility
Facility type of the process that logged the message.
bool parse_level_uppercase(const std::string &name, Level &level)
Parse an uppercase string to a log 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.
static constexpr bool thread_safe
Thread-safe status of the library.
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.
virtual void operator<<(std::shared_ptr< Message > message)=0
Add a new 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...
bool parse_level_lowercase(const std::string &name, Level &level)
Parse a lowercase string to a log level.
std::string format_timestamp_ms(uint64_t timestamp_ms, unsigned int days_width)
Format a system uptime timestamp as a string.
void emerg(const char *format,...) const
Log a message at level Level::EMERG.
friend Logger
Logger needs to be able to access the private reference to the registered log handlers.
void level(Level level)
Set the log level.
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::list< std::shared_ptr< Message > > log_messages_
const uint64_t uptime_ms
System uptime at the time the message was logged.
const std::string text
Formatted log message text.
void operator<<(std::shared_ptr< Message > message) override
Add a new log message.
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.