ARC SDK
Public Member Functions | Static Public Member Functions
Arc::LogFile Class Reference

A class for logging to files. More...

#include <arc/Logger.h>

Inheritance diagram for Arc::LogFile:
Arc::LogDestination

Public Member Functions

 LogFile (const std::string &path)
 Creates a LogFile connected to a file. More...
 
 ~LogFile ()
 Ordinary destructor. 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...
 
void Reopen ()
 Reopen file if currently open. 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...
 
- Public Member Functions inherited from Arc::LogDestination
void setFormat (const LogFormat &newformat)
 Set format for this log destination. More...
 
LogFormat getFormat () const
 Returns currently assigned format. More...
 
void setPrefix (const std::string &prefix)
 Set a prefix for this log destination to be logged before messages. More...
 
std::string getPrefix () const
 Returns currently assignd prefix. More...
 

Static Public Member Functions

static void ReopenAll ()
 Reopen all LogFile objects. More...
 
- Static Public Member Functions inherited from Arc::LogDestination
static void setDefaultFormat (const LogFormat &newformat)
 Set format for any new log destination. More...
 
static LogFormat getDefaultFormat ()
 Returns currently assigned default format. More...
 

Additional Inherited Members

- Protected Member Functions inherited from Arc::LogDestination
 LogDestination ()
 Default constructor. Protected since subclasses should be used instead. More...
 
- Protected Attributes inherited from Arc::LogDestination
Glib::Mutex mutex
 A mutex for synchronization. More...
 
LogFormat format
 Format to use in this LogDestination. More...
 
std::string prefix
 Prefix to use in this log destination. More...
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ LogFile()

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.

Parameters
pathThe path to file to which to write LogMessages.

◆ ~LogFile()

Arc::LogFile::~LogFile ( )

Ordinary destructor.

Member Function Documentation

◆ log()

virtual void Arc::LogFile::log ( const LogMessage message)
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.

Parameters
messageThe LogMessage to write.

Implements Arc::LogDestination.

◆ operator bool()

Arc::LogFile::operator bool ( void  )

Returns true if this instance is valid.

◆ operator!()

bool Arc::LogFile::operator! ( void  )

Returns true if this instance is invalid.

Python interface deviation
Method is unavailable in Python interface

◆ Reopen()

void Arc::LogFile::Reopen ( )

Reopen file if currently open.

◆ ReopenAll()

static void Arc::LogFile::ReopenAll ( )
static

Reopen all LogFile objects.

◆ setBackups()

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.

Parameters
newbackupNumber of backup files.

◆ setMaxSize()

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.

Parameters
newsizeMax size of log file.

◆ setReopen()

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.

Parameters
newreopenIf file to be reopened for every log record.

The documentation for this class was generated from the following file: