This class encapsulates syslog-like logging, but uses files instead of the syslog facility. More...
#include <DwmFileLogger.hh>
Public Types | |
| enum | BufferingType { e_notBuffered = _IONBF , e_lineBuffered = _IOLBF , e_blockBuffered = _IOFBF } |
Public Member Functions | |
| FileLogger () | |
| Constructor. | |
| ~FileLogger () | |
| Destructor. Closes the log if it's open. | |
| bool | Open (const std::string &ident, int logopt, const std::string &filename, BufferingType bufferingType=e_blockBuffered) |
| Opens the logger. | |
| std::string | FilePrefix () const |
| Returns the log file prefix, i.e. | |
| bool | IsOpen () const |
| Returns true if the logger is open, else returns false. | |
| bool | Close () |
| Closes the logger. | |
| bool | Log (int priority, const char *message,...) |
| Just like syslog(), takes a priority and a format string and variable list of arguments. | |
| bool | Log (const std::string &filename, int lineno, const std::string &function, int priority, const char *message,...) |
Like syslog(), but takes filename, lineno and function arguments which are usually FILE, LINE and PRETTY_FUNCTION in the caller source. | |
| bool | VaLog (int priority, const std::string &message, va_list &vaList) |
| Just like vsyslog(), takes a priority and a format string and a va_list. | |
| bool | VaLog (const std::string &filename, int lineno, const std::string &function, int priority, const std::string &message, va_list &vaList) |
Just like vsyslog(), but takes filename, lineno and function arguments which are usually FILE, LINE and PRETTY_FUNCTION in the caller source. | |
| bool | Flush () |
| Writes buffered data to the output log (i.e. | |
| int | MinimumPriority () const |
| Returns the lowest message priority that the logger will log. | |
| int | MinimumPriority (int minimumPriority) |
| Sets and returns the lowest message priority that the logger will log. | |
| bool | ShowPriorities () const |
| If the logger is set to show priorities in each log message, returns true. | |
| bool | ShowPriorities (bool showPriorities) |
If showPriorities is true, the logger will tag each log message with an indication of the message's priority. | |
| uint32_t | RolloverSize () const |
| Returns the current rollover size used by the logger. | |
| bool | ShowFunction () const |
| If the logger is set to show function information in Log(const string &, int, const string &, int, const char *, ...), returns true. | |
| bool | ShowFunction (bool showFunction) |
If showFunction is true, the logger will show function information in each log message logged with Log(const string &, int, const string &, int, const char *, ...). | |
| bool | ShowFileLocation () const |
| If the logger is set to show file location information, returns true. | |
| bool | ShowFileLocation (bool showFileLocation) |
If showFileLocation is true, the logger will show the file and line number information in each log message logged with Log(const string &, int, const string &, int, const char * , ...). | |
| uint32_t | RolloverSize (uint32_t rolloverSize) |
| Sets and returns the rollover size used by the logger. | |
| uint32_t | NumRolloverFiles () const |
| Returns the number of rollover files used by the logger. | |
| uint32_t | NumRolloverFiles (uint32_t numRolloverFiles) |
| Sets and returns the number of rollover files used by the logger. | |
| bool | SetPriorities (const std::map< int, std::pair< std::string, std::string > > &priorities) |
| Overrides the standard priority tags and names. | |
| std::string | PriorityTag (int priority) |
| Returns the priority tag ("[F]", "[W]", et. | |
Static Public Attributes | |
| static const uint32_t | k_defaultRolloverSize = 100 * 1024 |
| static const uint32_t | k_defaultNumRolloverFiles = 1 |
This class encapsulates syslog-like logging, but uses files instead of the syslog facility.
You may set the maximum size of the log file (in bytes) by using the RolloverSize(uint32_t) member. The default is 102400 (100K) bytes. You may set the number of rollover files using the NumRolloverFiles(uint32_t) member. The default is 1. The logger will roll over "logfile" to "logfile.0" and "logfile.N" to "logfile.N+1" for { 0 <= N < NumRolloverFiles() }. If the number of rollover files is set to 0, the log file will be truncated each time it grows beyond RolloverSize(). Note that RolloverSize() is only an estimate; the actual log size will be slightly larger since we treat log messages as atomic (we don't split them across files). You may set a priority threshold with MinimumPriority(int); any messages below this priority will be silently discarded. This allows dynamic logging levels, as well as allowing syslog.conf-like priority filtering functionality.
| std::string Dwm::FileLogger::FilePrefix | ( | ) | const |
Returns the log file prefix, i.e.
the filename argument that was given to Open().
| bool Dwm::FileLogger::Flush | ( | ) |
Writes buffered data to the output log (i.e.
flushes the buffer). Returns true on success, false on failure.
| bool Dwm::FileLogger::Log | ( | int | priority, |
| const char * | message, | ||
| ... ) |
Just like syslog(), takes a priority and a format string and variable list of arguments.
Returns true on success, false on failure.
| int Dwm::FileLogger::MinimumPriority | ( | int | minimumPriority | ) |
Sets and returns the lowest message priority that the logger will log.
By default, all message priorities will be logged (minimum priority == LOG_DEBUG).
| bool Dwm::FileLogger::Open | ( | const std::string & | ident, |
| int | logopt, | ||
| const std::string & | filename, | ||
| BufferingType | bufferingType = e_blockBuffered ) |
Opens the logger.
Returns true on success, false on failure. ident is used to name entries in the log (in the same manner as openlog()). logopt is the logging options, used in the same manner as the corresponding argument to openlog(). The acceptable log options are LOG_PID, LOG_CONS and LOG_NDELAY on all systems. LOG_PERROR is accepted on systems which support it. bufferingType specifies the desired buffering. Specifiy e_notBuffered to get unbuffered, e_lineBuffered to get line buffered, and e_blockBuffered to get fully buffered.
| std::string Dwm::FileLogger::PriorityTag | ( | int | priority | ) |
Returns the priority tag ("[F]", "[W]", et.
al.) for a given priority.
| uint32_t Dwm::FileLogger::RolloverSize | ( | uint32_t | rolloverSize | ) |
Sets and returns the rollover size used by the logger.
This is the number of bytes at which the logger will roll over the log files.
| bool Dwm::FileLogger::SetPriorities | ( | const std::map< int, std::pair< std::string, std::string > > & | priorities | ) |
Overrides the standard priority tags and names.
The key in priorities is the log priority (e.g. LOG_ERR), and each value is a (tag,name) pair, e.g. ("[E]", "error").
| bool Dwm::FileLogger::ShowFileLocation | ( | bool | showFileLocation | ) |
If showFileLocation is true, the logger will show the file and line number information in each log message logged with Log(const string &, int, const string &, int, const char * , ...).
If showFileLocation is false, the logger will not show file and line number information in log messages.
| bool Dwm::FileLogger::ShowFunction | ( | bool | showFunction | ) |
If showFunction is true, the logger will show function information in each log message logged with Log(const string &, int, const string &, int, const char *, ...).
If showFunction is false, the logger will not show function information in log messages.
| bool Dwm::FileLogger::ShowPriorities | ( | ) | const |
If the logger is set to show priorities in each log message, returns true.
Else returns false.
| bool Dwm::FileLogger::ShowPriorities | ( | bool | showPriorities | ) |
If showPriorities is true, the logger will tag each log message with an indication of the message's priority.
The tags are of the form "[x]" where x is a single letter. Hence we have "[M]" for LOG_EMERG, "[A]" for LOG_ALERT, "[C]" for LOG_CRIT, "[E]" for LOG_ERR, "[W]" for LOG_WARN, "[N]" for LOG_NOTICE, "[I]" for LOG_INFO and "[D]" for LOG_DEBUG. By default, message priorities are not shown.
| bool Dwm::FileLogger::VaLog | ( | const std::string & | filename, |
| int | lineno, | ||
| const std::string & | function, | ||
| int | priority, | ||
| const std::string & | message, | ||
| va_list & | vaList ) |
Just like vsyslog(), but takes filename, lineno and function arguments which are usually FILE, LINE and PRETTY_FUNCTION in the caller source.
Returns true on success, false on failure.
| bool Dwm::FileLogger::VaLog | ( | int | priority, |
| const std::string & | message, | ||
| va_list & | vaList ) |
Just like vsyslog(), takes a priority and a format string and a va_list.
Returns true on success, false on failure.