A multi-threaded logger for logging to one or more destinations.
More...
#include <Logger.h>
A multi-threaded logger for logging to one or more destinations.
A default logger is provided via madara::logger::global_logger in GlobalLogger.h
Definition at line 164 of file Logger.h.
◆ FileVectors
guard for access and changes
vector of file handles
Definition at line 308 of file Logger.h.
◆ Logger()
madara::logger::Logger::Logger |
( |
bool |
log_to_stderr = true | ) |
|
Constructor.
- Parameters
-
log_to_stderr | if true, log to stderr by default |
Definition at line 19 of file Logger.cpp.
◆ ~Logger()
madara::logger::Logger::~Logger |
( |
| ) |
|
◆ add_file()
void madara::logger::Logger::add_file |
( |
const std::string & |
filename | ) |
|
|
inline |
Adds a file to the logger.
- Parameters
-
filename | the file to open and add to writing |
Definition at line 12 of file Logger.inl.
◆ add_syslog()
void madara::logger::Logger::add_syslog |
( |
void |
| ) |
|
|
inline |
◆ add_term()
void madara::logger::Logger::add_term |
( |
void |
| ) |
|
|
inline |
Adds terminal to logger outputs.
Definition at line 104 of file Logger.inl.
◆ clear()
void madara::logger::Logger::clear |
( |
void |
| ) |
|
|
inline |
Clears all log targets.
Definition at line 118 of file Logger.inl.
◆ get_level()
int madara::logger::Logger::get_level |
( |
void |
| ) |
|
|
inline |
Gets the maximum logging detail level.
- Returns
- the maximum level of log detail
Definition at line 99 of file Logger.inl.
◆ get_tag()
std::string madara::logger::Logger::get_tag |
( |
void |
| ) |
|
|
inline |
Gets the tag used for syslogs.
- Returns
- the tag used for any system logging
Definition at line 44 of file Logger.inl.
◆ get_thread_level()
int madara::logger::Logger::get_thread_level |
( |
void |
| ) |
|
|
inlinestatic |
Fetches thread local storage value for thread level.
- Returns
- the log level of the local thread
Definition at line 85 of file Logger.inl.
◆ log()
void madara::logger::Logger::log |
( |
int |
level, |
|
|
const char * |
message, |
|
|
|
... |
|
) |
| |
Logs a message to all available loggers.
- Parameters
-
- See also
- LogLevels
- Parameters
-
message | the message to log |
Android seems to not handle printf arguments correctly as best I can tell
Prepare string to log for the timestamp prefix.
First, search and replace the custom key string for local thread. The return value is a copy of the potential prefix with the custom key string data embedded the number of times it was used.
Prepare string to write into copy of the message buffer.
Search and insert corresponding data for each of the custom key string.
Process the normal message buffer and write into final copy to return.
Definition at line 123 of file Logger.cpp.
◆ search_and_insert_custom_tstamp()
std::string madara::logger::Logger::search_and_insert_custom_tstamp |
( |
const std::string & |
buf, |
|
|
const std::string & |
ts_str |
|
) |
| |
|
private |
Set thread local storage value for hertz.
- Parameters
-
buf | - message buffer that holds the proprietary key key string. |
ts_str | - The key string to identify which values to replace |
- Returns
- the string containing the message data with key string data minus the actual key string
Take the ts_str (key string) and repeatedly search the incoming message buf.
If not found, npos is returned and exit the loop gracefully.
If found, compare via the series of if-else-if statements. Swap out the computed value with the key string using the copied message buffer
insert mgt text here get_time returns nsecs. need to convert into seconds.
insert this value into the buffer
convert the double into string format that can easily be written into the copy of the message buffer.
Definition at line 46 of file Logger.cpp.
◆ set_level()
void madara::logger::Logger::set_level |
( |
int |
level | ) |
|
|
inline |
Sets the maximum logging detail level.
- Parameters
-
level | the maximum level of log detail |
Definition at line 39 of file Logger.inl.
◆ set_tag()
void madara::logger::Logger::set_tag |
( |
const std::string & |
tag | ) |
|
|
inline |
Sets the tag used for syslogs (e.g.
Android Log)
- Parameters
-
tag | the tag to use for any system logging |
Definition at line 92 of file Logger.inl.
◆ set_timestamp_format()
void madara::logger::Logger::set_timestamp_format |
( |
const std::string & |
format = "%x %X: " | ) |
|
|
inline |
Sets timestamp format.
Uses strftime for formatting time.
- Parameters
-
format | the format of the timestamp. See C++ strftime definition for common usage. |
Definition at line 136 of file Logger.inl.
◆ strip_custom_tstamp()
std::string madara::logger::Logger::strip_custom_tstamp |
( |
const std::string |
in_str, |
|
|
const std::string |
ts_str |
|
) |
| |
|
private |
Set thread local storage value for hertz.
- Parameters
-
in_str | - input string to find potentially multiple instances of the key string |
ts_str | - actual key string to find. |
- Returns
- the string containing the message data with key string data
Definition at line 38 of file Logger.cpp.
◆ files_
list of all log outputs
Definition at line 314 of file Logger.h.
◆ level_
std::atomic<int> madara::logger::Logger::level_ |
|
private |
the maximum detail level for logging
Definition at line 317 of file Logger.h.
◆ MADARA_GET_TIME_MGT_
const char* madara::logger::Logger::MADARA_GET_TIME_MGT_ = "%MGT" |
|
private |
constants for the thread local keystrings
key string constant for clock seconds for local thread
Definition at line 334 of file Logger.h.
◆ MADARA_THREAD_HERTZ_
const char* madara::logger::Logger::MADARA_THREAD_HERTZ_ = "%MTZ" |
|
private |
key string cosntant for hertz value for local thread
Definition at line 340 of file Logger.h.
◆ MADARA_THREAD_NAME_
const char* madara::logger::Logger::MADARA_THREAD_NAME_ = "%MTN" |
|
private |
key string constant for thread name for local thread
Definition at line 337 of file Logger.h.
◆ mutex_
MADARA_LOCK_TYPE madara::logger::Logger::mutex_ |
|
mutableprivate |
mutex for changes
Definition at line 311 of file Logger.h.
◆ syslog_added_
bool madara::logger::Logger::syslog_added_ |
|
private |
tracks whether the system log has been added
Definition at line 323 of file Logger.h.
◆ tag_
std::string madara::logger::Logger::tag_ |
|
private |
the tag used for logging to system logs
Definition at line 326 of file Logger.h.
◆ term_added_
bool madara::logger::Logger::term_added_ |
|
private |
tracks whether terminal output has been added
Definition at line 320 of file Logger.h.
◆ timestamp_format_
std::string madara::logger::Logger::timestamp_format_ |
|
private |
the timestamp format.
Definition at line 329 of file Logger.h.
The documentation for this class was generated from the following files: