Public Member Functions | Private Attributes

nitro::LogStream Class Reference

Logging class. More...

#include <utilities/log_stream.h>

Collaboration diagram for nitro::LogStream:
Collaboration graph
[legend]

List of all members.

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)
LogStreamoperator<< (const char *LogString)
LogStreamoperator<< (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::MutexAbstractionLogMutex

Detailed Description

Logging class.

Author:
Dodonov A.A.

Definition at line 73 of file log_stream.h.


Constructor & Destructor Documentation

nitro::LogStream::LogStream ( const char *  theLogFilePath = NULL,
std::size_t  theSyncMode = ASYNC_LOGGING 
)

Function loads template from file.

Parameters:
theLogFilePath - Path to the log file.
theSyncMode - Syncronisation mode.
Exceptions:
nitro::exception Throws exception with the description of error.
Author:
Dodonov A.A.

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 ) );
                }
        }

Here is the call graph for this function:

nitro::LogStream::LogStream ( const std::string &  theLogFilePath,
std::size_t  theSyncMode = ASYNC_LOGGING 
)

Function loads template from file.

Parameters:
theLogFilePath - Path to the log file.
theSyncMode - Syncronisation mode.
Exceptions:
nitro::exception Throws exception with the description of error.
Author:
Dodonov A.A.

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 ) );
                }
        }

Here is the call graph for this function:

nitro::LogStream::~LogStream (  ) 

Destructor.

Author:
Dodonov A.A.

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 ) );
                }
        }

Here is the call graph for this function:


Member Function Documentation

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.

Parameters:
LogString - Outputting string.
Returns:
Object log.
Exceptions:
nitro::exception Throws exception with the description of error.
Author:
Dodonov A.A.

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 ) );
                }
        }

Here is the call graph for this function:

LogStream & nitro::LogStream::operator<< ( const std::string &  LogString  ) 

Method outputs string into log file.

Parameters:
LogString - Outputting string.
Returns:
Object log.
Exceptions:
nitro::exception Throws exception with the description of error.
Author:
Dodonov A.A.

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 ) );
                }
        }

Here is the call graph for this function:

void nitro::LogStream::Release ( void   ) 

Function releases log object.

Exceptions:
nitro::exception Throws exception with the description of error.
Author:
Dodonov A.A.

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 ) );
                }
        }

Here is the call graph for this function:

void nitro::LogStream::Reset ( const char *  theLogFilePath = NULL,
std::size_t  SyncMode = ASYNC_LOGGING 
)

Function resets object's properties.

Parameters:
theLogFilePath - Path to the log file.
SyncMode - Syncronisation mode.
Exceptions:
nitro::exception Throws exception with the description of error.
Author:
Dodonov A.A.

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 ) );
                }
        }

Here is the call graph for this function:

void nitro::LogStream::Reset ( const std::string &  theLogFilePath = NULL,
std::size_t  SyncMode = ASYNC_LOGGING 
)

Function resets object's properties.

Parameters:
theLogFilePath - Path to the log file.
SyncMode - Syncronisation mode.
Exceptions:
nitro::exception Throws exception with the description of error.
Author:
Dodonov A.A.

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 ) );
                }
        }

Here is the call graph for this function:


Member Data Documentation

Object provides file access routine.

Author:
Dodonov A.A.

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.

Author:
Dodonov A.A.

Definition at line 262 of file log_stream.h.

Referenced by LogStream(), operator<<(), and Reset().

Object provides file access routine.

Author:
Dodonov A.A.

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.

Author:
Dodonov A.A.

Definition at line 274 of file log_stream.h.

Referenced by LogStream(), operator<<(), and Reset().


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

Generated by  doxygen 1.6.1