1 #ifndef _MADARA_LOGGER_LOGGER_H_
2 #define _MADARA_LOGGER_LOGGER_H_
4 #include "madara/MadaraExport.h"
5 #include "madara/LockType.h"
20 #define madara_logger_log(loggering, level, ...) \
21 if (madara::logger::Logger::get_thread_level() >= 0) \
23 if (level <= madara::logger::Logger::get_thread_level()) \
25 loggering.log(level, __VA_ARGS__); \
28 else if (level <= loggering.get_level()) \
30 loggering.log(level, __VA_ARGS__); \
41 #define madara_logger_ptr_log(loggering, level, ...) \
42 if (madara::logger::Logger::get_thread_level() >= 0) \
44 if (level <= madara::logger::Logger::get_thread_level()) \
46 loggering->log(level, __VA_ARGS__); \
49 else if (level <= loggering->get_level()) \
51 loggering->log(level, __VA_ARGS__); \
62 #define madara_logger_checked_ptr_log(loggering, level, ...) \
63 if (loggering && madara::logger::Logger::get_thread_level() >= 0) \
65 if (level <= madara::logger::Logger::get_thread_level()) \
67 loggering->log(level, __VA_ARGS__); \
70 else if (loggering && level <= loggering->get_level()) \
72 loggering->log(level, __VA_ARGS__); \
83 #define madara_logger_cond_log_ptrs( \
84 conditional, logger_ptr, alt_logger_ptr, level, ...) \
86 (madara::logger::Logger::get_thread_level() >= 0)) \
88 if (level <= madara::logger::Logger::get_thread_level()) \
90 logger_ptr->log(level, __VA_ARGS__); \
94 alt_logger_ptr->log(level, __VA_ARGS__); \
97 else if (conditional && level <= logger_ptr->get_level()) \
99 logger_ptr->log(level, __VA_ARGS__); \
103 alt_logger_ptr->log(level, __VA_ARGS__); \
114 #define madara_logger_cond_log( \
115 conditional, loggering, alt_logger_ptr, level, ...) \
116 if (conditional && (madara::logger::Logger::get_thread_level() >= 0)) \
118 if (level <= madara::logger::Logger::get_thread_level()) \
120 loggering.log(level, __VA_ARGS__); \
124 alt_logger_ptr->log(level, __VA_ARGS__); \
127 else if (conditional && level <= loggering.get_level()) \
129 loggering.log(level, __VA_ARGS__); \
133 alt_logger_ptr->log(level, __VA_ARGS__); \
171 Logger(
bool log_to_stderr =
true);
183 void log(
int level,
const char* message, ...);
199 void add_syslog(
void);
205 void set_level(
int level);
237 void set_timestamp_format(
const std::string& format =
"%x %X: ");
243 static int get_thread_level(
void);
256 static double get_thread_hertz(
void);
262 static void set_thread_level(
int level);
268 static void set_thread_name(
const std::string name);
274 static void set_thread_hertz(
double hertz);
279 static thread_local
int thread_level_;
281 static thread_local
double thread_hertz_;
334 const char* MADARA_GET_TIME_MGT_ =
"%MGT";
337 const char* MADARA_THREAD_NAME_ =
"%MTN";
340 const char* MADARA_THREAD_HERTZ_ =
"%MTZ";
A multi-threaded logger for logging to one or more destinations.
std::string tag_
the tag used for logging to system logs
std::vector< FILE * > FileVectors
guard for access and changes
MADARA_LOCK_TYPE mutex_
mutex for changes
std::string timestamp_format_
the timestamp format.
bool syslog_added_
tracks whether the system log has been added
bool term_added_
tracks whether terminal output has been added
std::atomic< int > level_
the maximum detail level for logging
FileVectors files_
list of all log outputs
Provides knowledge logging services to files and terminals.
const int TLS_THREAD_LEVEL_DEFAULT
LogLevels
Logging levels available for MADARA library.
const double TLS_THREAD_HZ_DEFAULT
Copyright(c) 2020 Galois.