From bfa452a375ea0a0a3f95304a69186936567e5263 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Mon, 14 Aug 2023 19:45:36 +0200 Subject: New upstream version 4.1.4 --- src/core/xblog.cpp | 208 ----------------------------------------------------- 1 file changed, 208 deletions(-) delete mode 100755 src/core/xblog.cpp (limited to 'src/core/xblog.cpp') diff --git a/src/core/xblog.cpp b/src/core/xblog.cpp deleted file mode 100755 index 6031c9e..0000000 --- a/src/core/xblog.cpp +++ /dev/null @@ -1,208 +0,0 @@ -/* xblog.cpp - -XBase64 Software Library - -Copyright (c) 1997,2003,2014,2022 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 - -*/ - - -#include "xbase.h" -//#include - -#ifdef XB_LOGGING_SUPPORT - -namespace xb{ - -/******************************************************************************/ -//! @brief Constructor. -xbLog::xbLog() : xbFile( NULL ){ - - SetDirectory( GetLogDirectory()); - SetFileName ( GetLogFileName()); - - bLoggingStatus = xbFalse; - lLogSize = 50000; - - #ifdef XB_LOCKING_SUPPORT - iShareMode = XB_MULTI_USER; - #else - iShareMode = XB_SINGLE_USER; - #endif -} -/******************************************************************************/ -//! @brief Constructor. -/*! - \param sLogFileName - Log file name. -*/ -xbLog::xbLog( const xbString & sLogFileName ) : xbFile( NULL ){ - if( sLogFileName.GetPathSeparator()) - SetFqFileName( sLogFileName ); // file name includes a path - else - SetFileName( sLogFileName ); // no file path - - bLoggingStatus = xbFalse; - lLogSize = 50000; - - #ifdef XB_LOCKING_SUPPORT - iShareMode = XB_MULTI_USER; - #else - iShareMode = XB_SINGLE_USER; - #endif - -} -/******************************************************************************/ -//! @brief Deconstructor. -xbLog::~xbLog(){ - xbFclose(); -} -/******************************************************************************/ -//! @brief Get the current log status -/*! - \returns xbTrue - Logging turned on.
xbFalse - Logging turned off. -*/ -xbBool xbLog::LogGetStatus(){ - return bLoggingStatus; -} -/******************************************************************************/ -//! @brief Close the logfile. -/*! - \returns Return Codes -*/ -xbInt16 xbLog::LogClose(){ - return xbFclose(); -} -/******************************************************************************/ -//! @brief Set maximum log file size. -/*! - \param lSize - New maximum log file size. - \returns void -*/ -void xbLog::LogSetLogSize( size_t lSize ){ - lLogSize = lSize; -} -/******************************************************************************/ -//! @brief Set log status. -/*! - \param bStatus xbTrue - Turn logging on.
xbFalse - Turn logging off. - \returns void -*/ -void xbLog::LogSetStatus( xbBool bStatus ){ - bLoggingStatus = bStatus; -} -/******************************************************************************/ -//! @brief Open the logfile. -/*! - \returns Return Codes -*/ -xbInt16 xbLog::LogOpen(){ - xbInt16 rc; - if(( rc = xbFopen( "a", iShareMode )) != XB_NO_ERROR ) - return rc; - xbFTurnOffFileBuffering(); - return XB_NO_ERROR; -} -/******************************************************************************/ -//! @brief Write a logfile message. -/*! - \param sLogEntryData - Message to write to the logfile. - \param iOutputOption 0 - Write to logfile.
- 1 - Write to stdout.
- 2 - Write to both logfile and stdout. - \returns Return Codes -*/ - -xbInt16 xbLog::LogWrite( const xbString &sLogEntryData, xbInt16 iOutputOption ){ - - if( bLoggingStatus == xbFalse ){ // logging turned off - return XB_NO_ERROR; - } - xbInt16 rc = 0; - if( iOutputOption != 1 && !FileIsOpen() ){ - if(( rc = LogOpen()) != XB_NO_ERROR ){ - fprintf( stderr, "Error - cant write to logfile\n" ); - return rc; - } - } - if( iOutputOption != 1 && lLogSize < xbFtell()){ - xbFputs( "Swapping to next log file" ); - xbFclose(); - xbString sBackupName; - sBackupName.Sprintf( "%s.bak", GetFqFileName().Str()); - if( FileExists( sBackupName )) - xbRemove( sBackupName ); - - xbRename( GetFqFileName(), sBackupName ); - xbFopen( "a", iShareMode ); - } - xbString sTimeStamp; - xbString sFled; // formatted log entry data - - if( iOutputOption != 1 ){ - #ifdef HAVE__LOCALTIME64_S_F - __time64_t timer; - struct tm tb; - _time64( &timer ); - _localtime64_s( &tb, &timer ); - tb.tm_year += 1900; - tb.tm_mon++; - sTimeStamp.Sprintf( "%4d-%02d-%02d %02d:%02d:%02d", tb.tm_year, tb.tm_mon, tb.tm_mday, tb.tm_hour, tb.tm_min, tb.tm_sec ); - #else - time_t timer; - struct tm *tb; - timer = time( NULL ); - tb = localtime( &timer ); - tb->tm_year += 1900; - tb->tm_mon++; - sTimeStamp.Sprintf( "%4d-%02d-%02d %02d:%02d:%02d", tb->tm_year, tb->tm_mon, tb->tm_mday, tb->tm_hour, tb->tm_min, tb->tm_sec ); - #endif - sFled.Sprintf( "%s - %s\n", sTimeStamp.Str(), sLogEntryData.Str() ); - } - - switch( iOutputOption ){ - case 0: - xbFputs( sFled ); - break; - case 1: - std::cout << sLogEntryData << std::endl; - break; - case 2: - xbFputs( sFled ); - std::cout << sLogEntryData << std::endl; - break; - } - return XB_NO_ERROR; -} -/******************************************************************************/ -//! @brief Write bytes to logfile. -/*! - \param ulByteCnt - Number of bytes to write to logfile. - \param p - Pointer to data to write to logfile. - \returns XB_NO_ERROR -*/ - -xbInt16 xbLog::LogWriteBytes( xbUInt32 ulByteCnt, const char *p ){ - - if( bLoggingStatus == xbFalse ) // logging turned off - return XB_NO_ERROR; - const char *p2 = p; - xbFputc( '[' ); - for( xbUInt32 l = 0; l < ulByteCnt; l++ ) - xbFputc( *p2++ ); - xbFputc( ']' ); - return XB_NO_ERROR; -} -/******************************************************************************/ -} // namespace -#endif // XB_LOGGING_ON - - - - -- cgit v1.2.3 From c894a7cdd8686ea695602a23a511a3f1b0d047be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Mon, 14 Aug 2023 21:07:46 +0200 Subject: New upstream version 4.1.4 --- src/core/xblog.cpp | 227 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 227 insertions(+) create mode 100755 src/core/xblog.cpp (limited to 'src/core/xblog.cpp') diff --git a/src/core/xblog.cpp b/src/core/xblog.cpp new file mode 100755 index 0000000..9443006 --- /dev/null +++ b/src/core/xblog.cpp @@ -0,0 +1,227 @@ +/* xblog.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 + +*/ + + +#include "xbase.h" +//#include + +#ifdef XB_LOGGING_SUPPORT + +namespace xb{ + +/******************************************************************************/ +//! @brief Constructor. +xbLog::xbLog() : xbFile( NULL ){ + + + // std::cout << "xbLog::xbLog(1) Directory = [" << GetLogDirectory() << "]\n"; + // std::cout << "xbLog::xbLog(1) Name = [" << GetLogFileName() << "]\n"; + + SetDirectory( GetLogDirectory()); + SetFileName ( GetLogFileName()); + + bLoggingStatus = xbFalse; + lLogSize = 100000; + + #ifdef XB_LOCKING_SUPPORT + iShareMode = XB_MULTI_USER; + #else + iShareMode = XB_SINGLE_USER; + #endif +} +/******************************************************************************/ +//! @brief Constructor. +/*! + \param sLogFileName - Log file name. +*/ +xbLog::xbLog( const xbString & sLogFileName ) : xbFile( NULL ){ + if( sLogFileName.GetPathSeparator()) + SetFqFileName( sLogFileName ); // file name includes a path + else + SetFileName( sLogFileName ); // no file path + + bLoggingStatus = xbFalse; + lLogSize = 100000; + + #ifdef XB_LOCKING_SUPPORT + iShareMode = XB_MULTI_USER; + #else + iShareMode = XB_SINGLE_USER; + #endif + +} +/******************************************************************************/ +//! @brief Deconstructor. +xbLog::~xbLog(){ + xbFclose(); +} +/******************************************************************************/ +//! @brief Get the current log status +/*! + \returns xbTrue - Logging turned on.
xbFalse - Logging turned off. +*/ +xbBool xbLog::LogGetStatus(){ + return bLoggingStatus; +} +/******************************************************************************/ +//! @brief Close the logfile. +/*! + \returns Return Codes +*/ +xbInt16 xbLog::LogClose(){ + return xbFclose(); +} +/******************************************************************************/ +//! @brief Set maximum log file size. +/*! + \param lSize - New maximum log file size. + \returns void +*/ +void xbLog::LogSetLogSize( size_t lSize ){ + lLogSize = lSize; +} +/******************************************************************************/ +//! @brief Set log status. +/*! + \param bStatus xbTrue - Turn logging on.
xbFalse - Turn logging off. + \returns void +*/ +void xbLog::LogSetStatus( xbBool bStatus ){ + if( bLoggingStatus && !bStatus ) + LogClose(); + bLoggingStatus = bStatus; +} +/******************************************************************************/ +//! @brief Open the logfile. +/*! + \returns Return Codes +*/ +xbInt16 xbLog::LogOpen(){ + xbInt16 rc; + +// std::cout << "*****\nxbLog::LogOpen(1) GetLogDirectory = " << GetLogDirectory() << "\n"; +// std::cout << "xbLog::LogOpen(1) GetLogFileName = " << GetLogFileName() << "\n"; +// std::cout << "xbLog::GetFqFileName(1) = " << GetFqFileName() << "\n\n"; + + // 4.1.3 added next two lines for dynamic log file name changing + SetDirectory( GetLogDirectory()); + SetFileName ( GetLogFileName()); + +// std::cout << "*****\nxbLog::LogOpen(2) GetLogDirectory = " << GetLogDirectory() << "\n"; +// std::cout << "xbLog::LogOpen(2) GetLogFileName = " << GetLogFileName() << "\n"; +// std::cout << "xbLog::GetFqFileName(2) = " << GetFqFileName() << "\n\n"; + + if(( rc = xbFopen( "a", iShareMode )) != XB_NO_ERROR ) + return rc; + xbFTurnOffFileBuffering(); + return XB_NO_ERROR; +} +/******************************************************************************/ +//! @brief Write a logfile message. +/*! + \param sLogEntryData - Message to write to the logfile. + \param iOutputOption 0 - Write to logfile.
+ 1 - Write to stdout.
+ 2 - Write to both logfile and stdout. + \returns Return Codes +*/ + +xbInt16 xbLog::LogWrite( const xbString &sLogEntryData, xbInt16 iOutputOption ){ + + if( bLoggingStatus == xbFalse ){ // logging turned off + return XB_NO_ERROR; + } + xbInt16 rc = 0; + if( iOutputOption != 1 && !FileIsOpen() ){ + if(( rc = LogOpen()) != XB_NO_ERROR ){ + fprintf( stderr, "Error - cant write to logfile\n" ); + return rc; + } + } + if( iOutputOption != 1 && lLogSize < xbFtell()){ + xbFputs( "Swapping to next log file" ); + xbFclose(); + xbString sBackupName; + sBackupName.Sprintf( "%s.bak", GetFqFileName().Str()); + if( FileExists( sBackupName )) + xbRemove( sBackupName ); + + xbRename( GetFqFileName(), sBackupName ); + xbFopen( "a", iShareMode ); + } + xbString sTimeStamp; + xbString sFled; // formatted log entry data + + if( iOutputOption != 1 ){ + #ifdef HAVE__LOCALTIME64_S_F + __time64_t timer; + struct tm tb; + _time64( &timer ); + _localtime64_s( &tb, &timer ); + tb.tm_year += 1900; + tb.tm_mon++; + sTimeStamp.Sprintf( "%4d-%02d-%02d %02d:%02d:%02d", tb.tm_year, tb.tm_mon, tb.tm_mday, tb.tm_hour, tb.tm_min, tb.tm_sec ); + #else + time_t timer; + struct tm *tb; + timer = time( NULL ); + tb = localtime( &timer ); + tb->tm_year += 1900; + tb->tm_mon++; + sTimeStamp.Sprintf( "%4d-%02d-%02d %02d:%02d:%02d", tb->tm_year, tb->tm_mon, tb->tm_mday, tb->tm_hour, tb->tm_min, tb->tm_sec ); + #endif + sFled.Sprintf( "%s - %s\n", sTimeStamp.Str(), sLogEntryData.Str() ); + } + + switch( iOutputOption ){ + case 0: + xbFputs( sFled ); + break; + case 1: + std::cout << sLogEntryData << std::endl; + break; + case 2: + xbFputs( sFled ); + std::cout << sLogEntryData << std::endl; + break; + } + return XB_NO_ERROR; +} +/******************************************************************************/ +//! @brief Write bytes to logfile. +/*! + \param ulByteCnt - Number of bytes to write to logfile. + \param p - Pointer to data to write to logfile. + \returns XB_NO_ERROR +*/ + +xbInt16 xbLog::LogWriteBytes( xbUInt32 ulByteCnt, const char *p ){ + + if( bLoggingStatus == xbFalse ) // logging turned off + return XB_NO_ERROR; + const char *p2 = p; + xbFputc( '[' ); + for( xbUInt32 l = 0; l < ulByteCnt; l++ ) + xbFputc( *p2++ ); + xbFputc( ']' ); + return XB_NO_ERROR; +} +/******************************************************************************/ +} // namespace +#endif // XB_LOGGING_ON + + + + -- cgit v1.2.3