41#ifndef _DWMFILELOGGER_HH_
42#define _DWMFILELOGGER_HH_
77 e_notBuffered = _IONBF,
78 e_lineBuffered = _IOLBF,
79 e_blockBuffered = _IOFBF
82 static const uint32_t k_defaultRolloverSize = 100 * 1024;
83 static const uint32_t k_defaultNumRolloverFiles = 1;
107 bool Open(
const std::string & ident,
int logopt,
108 const std::string & filename,
109 BufferingType bufferingType = e_blockBuffered);
132 bool Log(
int priority,
const char * message, ...);
139 bool Log(
const std::string & filename,
int lineno,
140 const std::string & function,
int priority,
141 const char * message, ...);
147 bool VaLog(
int priority,
const std::string & message,
156 bool VaLog(
const std::string & filename,
int lineno,
157 const std::string & function,
int priority,
158 const std::string & message, va_list & vaList);
253 bool SetPriorities(
const std::map<
int, std::pair<std::string,std::string> > & priorities);
263 int _minimumPriority;
265 bool _showPriorities;
267 bool _showFileLocation;
268 std::string _hostName;
269 std::string _filePrefix;
272 uint32_t _numRolloverFiles;
273 off_t _currentFilePosition;
274 BufferingType _bufferingType;
276 mutable std::mutex _mutex;
277 std::map<std::string,int> _priorityNames;
278 std::map<int,std::string> _priorityTags;
280 static const std::map<std::string,int> _defaultPriorityNames;
281 static const std::map<int,std::string> _defaultPriorityTags;
286 bool OpenNoLock(
const std::string & ident,
int logopt,
287 const std::string & filename,
288 BufferingType bufferingType = e_blockBuffered);
289 bool OpenFile(
const std::string & filename);
290 bool RollFilesOver();
291 void InitializePriorities();
This class encapsulates syslog-like logging, but uses files instead of the syslog facility.
Definition DwmFileLogger.hh:74
bool SetPriorities(const std::map< int, std::pair< std::string, std::string > > &priorities)
Overrides the standard priority tags and names.
bool ShowFileLocation(bool showFileLocation)
If showFileLocation is true, the logger will show the file and line number information in each log me...
~FileLogger()
Destructor. Closes the log if it's open.
bool ShowPriorities(bool showPriorities)
If showPriorities is true, the logger will tag each log message with an indication of the message's p...
std::string FilePrefix() const
Returns the log file prefix, i.e.
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,...
bool ShowFunction(bool showFunction)
If showFunction is true, the logger will show function information in each log message logged with Lo...
bool IsOpen() const
Returns true if the logger is open, else returns false.
int MinimumPriority(int minimumPriority)
Sets and returns the lowest message priority that the logger will log.
uint32_t RolloverSize() const
Returns the current rollover size used by the logger.
uint32_t NumRolloverFiles(uint32_t numRolloverFiles)
Sets and returns the number of rollover files used by the logger.
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,...
bool ShowFunction() const
If the logger is set to show function information in Log(const string &, int, const string &,...
bool Open(const std::string &ident, int logopt, const std::string &filename, BufferingType bufferingType=e_blockBuffered)
Opens the logger.
bool ShowFileLocation() const
If the logger is set to show file location information, returns true.
bool ShowPriorities() const
If the logger is set to show priorities in each log message, returns true.
bool Flush()
Writes buffered data to the output log (i.e.
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.
std::string PriorityTag(int priority)
Returns the priority tag ("[F]", "[W]", et.
uint32_t NumRolloverFiles() const
Returns the number of rollover files used by the logger.
bool Log(int priority, const char *message,...)
Just like syslog(), takes a priority and a format string and variable list of arguments.
uint32_t RolloverSize(uint32_t rolloverSize)
Sets and returns the rollover size used by the logger.
int MinimumPriority() const
Returns the lowest message priority that the logger will log.
bool Close()
Closes the logger.