ARC SDK
|
A class for logging to files. More...
#include <arc/Logger.h>
Public Member Functions | |
LogFile (const std::string &path) | |
Creates a LogFile connected to a file. More... | |
void | setMaxSize (int newsize) |
Set maximal allowed size of file. More... | |
void | setBackups (int newbackup) |
Set number of backups to store. More... | |
void | setReopen (bool newreopen) |
Set file reopen on every write. More... | |
operator bool (void) | |
Returns true if this instance is valid. More... | |
bool | operator! (void) |
Returns true if this instance is invalid. More... | |
virtual void | log (const LogMessage &message) |
Writes a LogMessage to the file. More... | |
![]() | |
void | setFormat (const LogFormat &newformat) |
Set format for this log destination. More... | |
void | setPrefix (const std::string &prefix) |
Set a prefix for this log destination to be logged before messages. More... | |
Additional Inherited Members | |
![]() | |
LogDestination () | |
Default constructor. Protected since subclasses should be used instead. More... | |
![]() | |
LogFormat | format |
Format to use in this LogDestination. More... | |
std::string | prefix |
Prefix to use in this log destination. More... | |
A class for logging to files.
This class is used for logging to files. It provides synchronization in order to prevent different LogMessages to appear mixed with each other in the stream. It is possible to limit size of created file. Whenever specified size is exceeded file is deleted and new one is created. Old files may be moved into backup files instead of being deleted. Those files have names same as initial file with additional number suffix - similar to those found in /var/log of many Unix-like systems.
Arc::LogFile::LogFile | ( | const std::string & | path | ) |
Creates a LogFile connected to a file.
Creates a LogFile connected to the file located at specified path. In order not to break synchronization, it is important not to connect more than one LogFile object to a certain file. If file does not exist it will be created.
path | The path to file to which to write LogMessages. |
|
virtual |
Writes a LogMessage to the file.
This method writes a LogMessage to the file that is connected to this LogFile object. If after writing size of file exceeds one set by setMaxSize() file is moved to backup and new one is created.
message | The LogMessage to write. |
Implements Arc::LogDestination.
Arc::LogFile::operator bool | ( | void | ) |
Returns true if this instance is valid.
bool Arc::LogFile::operator! | ( | void | ) |
Returns true if this instance is invalid.
void Arc::LogFile::setBackups | ( | int | newbackup | ) |
Set number of backups to store.
Set number of backups to store. When file size exceeds one specified with setMaxSize() file is closed and moved to one named path.1. If path.1 exists it is moved to path.2 and so on. Number of path.# files is one set in newbackup.
newbackup | Number of backup files. |
void Arc::LogFile::setMaxSize | ( | int | newsize | ) |
Set maximal allowed size of file.
Set maximal allowed size of file. This value is not obeyed exactly. Specified size may be exceeded by amount of one LogMessage. To disable limit specify -1.
newsize | Max size of log file. |
void Arc::LogFile::setReopen | ( | bool | newreopen | ) |
Set file reopen on every write.
Set file reopen on every write. If set to true file is opened before writing every log record and closed afterward.
newreopen | If file to be reopened for every log record. |