Logging

Chapter Updated 04/28/23




The objective of this chapter is to provide information regarding the logging funcitionality contained within the Xbase64 library.

When the Xbase64 generates an error, it writes an entry in the logfile if logging is enabled. The library generates an error mesage with an error code value and an error stop value. The error code identifies what the error is, the error stop identifies where it errored in the libary.

The xbLog class supports the following functionality:

  • Error and message logging.
  • Rolling log files. When log file fills, full file is closed and new file is opened.
  • Configurable size.
  • Configurable name.
  • Configurable location.


    Default Logfile Settings:

    SettingDefault ValueInitialization Source
    Folder:#define PROJECT_LOG_DIRCMakelists.txt
    Name:#define PROJECT_DFLT_LOGFILExbconfig.h.in
    Size:100000xbLog::xbLog()




    The logfile is controlled by the main xbXBase class via the methods listed in the table below. To change the logfile location or name or size, use the DisableMsgLogging() and EnableMessageLogging() to get the updates to take effect.

    Methods for managing the logfile

    MethodDescription
    xbString& xbSsv::GetLogDirectory() constGet the log file directory.
    xbString& xbSsv::GetLogFileName() constGet the log file name.
    xbString& xbSsv::SetLogDirectory( const xbString &sLogDirectory )Set the log file directory.
    void xbSsv::SetLogFileName( const xbString &sLogFileName )Set the log file name.
    void xbXBase::DisableMsgLogging()Disable message logging.
    void xbXBase::EnableMsgLogging()Enable message logging.
    xbInt16 xbXBase::FlushLog()Flush any buffered log file messages to disk.
    const xbXBase::xbString &GetLogFqFileName() constGet fully qualified logfile name.
    size_t xbXBase::GetLogSize() constGet the log file roll over size.
    xbBool xbXBase::GetLogStatus() constGet the logging file status.
    void xbXBase::SetLogSize( size_t lSize )Set the logfile roll over size.


    Example program demonstrating logfile related methods.

    /* xb_ex_log.cpp XBase64 Software Library Copyright (c) 1997,2003,2014,2022,2023 Gary A Kunkel The xb64 software library is covered under the terms of the GPL Version 3, 2007 license. Email Contact: XDB-devel@lists.sourceforge.net XDB-users@lists.sourceforge.net */ // This program demostrates how to use logging #include "xbase.h" using namespace xb; int main( int argCnt, char **av ) { #ifdef XB_LOGGING_SUPPORT xbXBase x; xbString sMsg; std::cout << "Default Logfile Name is: [" << x.GetLogFqFileName().Str() << "] Rollover size = [" << x.GetLogSize() << "]" << std::endl; if( x.GetLogStatus() ) std::cout << "Logging is active" << std::endl; else std::cout << "Logging is inactive" << std::endl; x.SetLogDirectory( PROJECT_LOG_DIR ); // use the library log directory x.SetLogFileName ( "MySpecialLogFile.txt" ); // set to use a special name x.SetLogSize ( x.GetLogSize() * 2 ); // double the log file size // enable the logfile and write a message for the new settings to take effect x.EnableMsgLogging(); sMsg.Sprintf( "Program [%s] initializing...", av[0] ); x.WriteLogMessage( sMsg ); std::cout << "New Logfile Name is: [" << x.GetLogFqFileName().Str() << "] Rollover size = [" << x.GetLogSize() << "]" << std::endl; if( x.GetLogStatus() ) std::cout << "Logging is active" << std::endl; else std::cout << "Logging is inactive" << std::endl; // write some messages to the logfile for( int i = 0; i < 5; i++ ){ sMsg.Sprintf( "Test message [%d]", i ); x.WriteLogMessage( sMsg ); } sMsg.Sprintf( "Program [%s] terminating..", av[0] ); x.WriteLogMessage( sMsg ); x.FlushLog(); // not really needed, but here for demonstration purposes #endif // B_LOGGING_SUPPORT return 0; }