Logging class. More...
#include <utilities/log_stream.h>
Public Member Functions | |
LogStream (const char *theLogFilePath=NULL, std::size_t theSyncMode=ASYNC_LOGGING) | |
LogStream (const std::string &theLogFilePath, std::size_t theSyncMode=ASYNC_LOGGING) | |
LogStream & | operator<< (const char *LogString) |
LogStream & | operator<< (const std::string &LogString) |
void | Reset (const char *theLogFilePath=NULL, std::size_t SyncMode=ASYNC_LOGGING) |
ALIAS_FUNCTION_2 (Reset, aliasReset, const char *, std::size_t) | |
void | Reset (const std::string &theLogFilePath=NULL, std::size_t SyncMode=ASYNC_LOGGING) |
void | Release (void) |
~LogStream () | |
Private Attributes | |
std::string | LogFilePath |
std::size_t | SyncMode |
nitro::FileAbstraction | FileAccessObject |
nitro::MutexAbstraction * | LogMutex |
Logging class.
Definition at line 73 of file log_stream.h.
nitro::LogStream::LogStream | ( | const char * | theLogFilePath = NULL , |
|
std::size_t | theSyncMode = ASYNC_LOGGING | |||
) |
Function loads template from file.
theLogFilePath | - Path to the log file. | |
theSyncMode | - Syncronisation mode. |
nitro::exception | Throws exception with the description of error. |
Definition at line 10 of file log_stream.cpp.
References nitro::exception::code(), LogFilePath, LogMutex, SyncMode, and nitro::exception::what().
{ try { if( theLogFilePath == NULL ) { LogFilePath = "./system.log"; } else { LogFilePath = theLogFilePath; } SyncMode = theSyncMode; LogMutex = NULL; } catch( nitro::exception e ) { throw( nitro::exception( std::string( "LogStream::LogStream( const char * theLogFilePath /* = NULL */ , std::size_t theSyncMode /* = ASYNC_LOGGING */ )::" ) + e.what() , e.code() ) ); } catch( ... ) { throw( nitro::exception( std::string( "LogStream::LogStream( const char * theLogFilePath /* = NULL */ , std::size_t theSyncMode /* = ASYNC_LOGGING */ )::An error occured" ) , 0 ) ); } }
nitro::LogStream::LogStream | ( | const std::string & | theLogFilePath, | |
std::size_t | theSyncMode = ASYNC_LOGGING | |||
) |
Function loads template from file.
theLogFilePath | - Path to the log file. | |
theSyncMode | - Syncronisation mode. |
nitro::exception | Throws exception with the description of error. |
Definition at line 35 of file log_stream.cpp.
References nitro::exception::code(), LogFilePath, LogMutex, SyncMode, and nitro::exception::what().
{ try { if( theLogFilePath == "" ) { LogFilePath = "./system.log"; } else { LogFilePath = theLogFilePath; } SyncMode = theSyncMode; LogMutex = NULL; } catch( nitro::exception e ) { throw( nitro::exception( std::string( "LogStream::LogStream( const std::string & theLogFilePath , std::size_t theSyncMode /* = ASYNC_LOGGING */ )::" ) + e.what() , e.code() ) ); } catch( ... ) { throw( nitro::exception( std::string( "LogStream::LogStream( const std::string & theLogFilePath , std::size_t theSyncMode /* = ASYNC_LOGGING */ )::An error occured" ) , 0 ) ); } }
nitro::LogStream::~LogStream | ( | ) |
Destructor.
Definition at line 187 of file log_stream.cpp.
References nitro::exception::code(), Release(), and nitro::exception::what().
{ try { Release(); } catch( nitro::exception e ) { throw( nitro::exception( std::string( "LogStream::~LogStream()::" ) + e.what() , e.code() ) ); } catch( ... ) { throw( nitro::exception( std::string( "LogStream::~LogStream()::An error occured" ) , 0 ) ); } }
nitro::LogStream::ALIAS_FUNCTION_2 | ( | Reset | , | |
aliasReset | , | |||
const char * | , | |||
std::size_t | ||||
) |
LogStream & nitro::LogStream::operator<< | ( | const char * | LogString | ) |
Method outputs string into log file.
LogString | - Outputting string. |
nitro::exception | Throws exception with the description of error. |
Definition at line 60 of file log_stream.cpp.
References nitro::exception::code(), FileAccessObject, nitro::MutexAbstraction::Lock(), LogFilePath, LogMutex, Reset(), SyncMode, nitro::MutexAbstraction::UnLock(), nitro::exception::what(), and nitro::FileAbstraction::Write().
{ try { if( SyncMode != 2 ) { Reset( LogFilePath.c_str() , SyncMode ); SyncMode = 2; } if( LogMutex ) { LogMutex->Lock(); } FileAccessObject.Write( LogString , strlen( LogString ) ); if( LogMutex ) { LogMutex->UnLock(); } return( * this ); } catch( nitro::exception e ) { throw( nitro::exception( std::string( "LogStream::operator<<( const char * LogString )::" ) + e.what() , e.code() ) ); } catch( ... ) { throw( nitro::exception( std::string( "LogStream::operator<<( const char * LogString )::An error occured" ) , 0 ) ); } }
LogStream & nitro::LogStream::operator<< | ( | const std::string & | LogString | ) |
Method outputs string into log file.
LogString | - Outputting string. |
nitro::exception | Throws exception with the description of error. |
Definition at line 94 of file log_stream.cpp.
References nitro::exception::code(), and nitro::exception::what().
{ try { return( ( * this ) << LogString.c_str() ); } catch( nitro::exception e ) { throw( nitro::exception( std::string( "LogStream::operator<<( const std::string & LogString )::" ) + e.what() , e.code() ) ); } catch( ... ) { throw( nitro::exception( std::string( "LogStream::operator<<( const std::string & LogString )::An error occured" ) , 0 ) ); } }
void nitro::LogStream::Release | ( | void | ) |
Function releases log object.
nitro::exception | Throws exception with the description of error. |
Definition at line 164 of file log_stream.cpp.
References nitro::FileAbstraction::Close(), nitro::exception::code(), FileAccessObject, LogMutex, nitro::MutexAbstraction::Release(), and nitro::exception::what().
Referenced by Reset(), and ~LogStream().
{ try { if( LogMutex ) { LogMutex->Release(); delete LogMutex; LogMutex = NULL; } FileAccessObject.Close(); } catch( nitro::exception e ) { throw( nitro::exception( std::string( "LogStream::Release( void )::" ) + e.what() , e.code() ) ); } catch( ... ) { throw( nitro::exception( std::string( "LogStream::Release( void )::An error occured" ) , 0 ) ); } }
void nitro::LogStream::Reset | ( | const char * | theLogFilePath = NULL , |
|
std::size_t | SyncMode = ASYNC_LOGGING | |||
) |
Function resets object's properties.
theLogFilePath | - Path to the log file. | |
SyncMode | - Syncronisation mode. |
nitro::exception | Throws exception with the description of error. |
Definition at line 110 of file log_stream.cpp.
References nitro::exception::code(), nitro::MutexAbstraction::CreateMutex(), nitro::FA_FILE_APPEND, nitro::FA_FILE_BINARY, nitro::FA_FILE_WRITE, FileAccessObject, LogFilePath, LogMutex, nitro::FileAbstraction::Open(), Release(), nitro::SYNC_LOGGING, SyncMode, and nitro::exception::what().
Referenced by operator<<(), and Reset().
{ try { Release(); if( theLogFilePath == NULL ) { LogFilePath = "./system.log"; } else { LogFilePath = theLogFilePath; } SyncMode = theSyncMode; if( SyncMode == nitro::SYNC_LOGGING ) { LogMutex = new nitro::MutexAbstraction(); LogMutex->CreateMutex(); } else { LogMutex = NULL; } FileAccessObject.Open( LogFilePath , nitro::FA_FILE_BINARY | nitro::FA_FILE_WRITE | FA_FILE_APPEND ); } catch( nitro::exception e ) { throw( nitro::exception( std::string( "LogStream::Reset( const char * LogFilePath /* = NULL */ , std::size_t SyncMode /* = ASYNC_LOGGING */ )::" ) + e.what() , e.code() ) ); } catch( ... ) { throw( nitro::exception( std::string( "LogStream::Reset( const char * LogFilePath /* = NULL */ , std::size_t SyncMode /* = ASYNC_LOGGING */ )::An error occured" ) , 0 ) ); } }
void nitro::LogStream::Reset | ( | const std::string & | theLogFilePath = NULL , |
|
std::size_t | SyncMode = ASYNC_LOGGING | |||
) |
Function resets object's properties.
theLogFilePath | - Path to the log file. | |
SyncMode | - Syncronisation mode. |
nitro::exception | Throws exception with the description of error. |
Definition at line 148 of file log_stream.cpp.
References nitro::exception::code(), Reset(), and nitro::exception::what().
{ try { Reset( theLogFilePath.c_str() , theSyncMode ); } catch( nitro::exception e ) { throw( nitro::exception( std::string( "LogStream::Reset( const std::string & theLogFilePath /* = NULL */ , std::size_t theSyncMode /* = ASYNC_LOGGING */ )::" ) + e.what() , e.code() ) ); } catch( ... ) { throw( nitro::exception( std::string( "LogStream::Reset( const std::string & theLogFilePath /* = NULL */ , std::size_t theSyncMode /* = ASYNC_LOGGING */ )::An error occured" ) , 0 ) ); } }
Object provides file access routine.
Definition at line 286 of file log_stream.h.
Referenced by operator<<(), Release(), and Reset().
std::string nitro::LogStream::LogFilePath [private] |
Path to the log file.
Definition at line 262 of file log_stream.h.
Referenced by LogStream(), operator<<(), and Reset().
Object provides file access routine.
Definition at line 298 of file log_stream.h.
Referenced by LogStream(), operator<<(), Release(), and Reset().
std::size_t nitro::LogStream::SyncMode [private] |
Sync mode.
Definition at line 274 of file log_stream.h.
Referenced by LogStream(), operator<<(), and Reset().