OpenM++ runtime library (libopenm)
Loading...
Searching...
No Matches
openm::LogBase Class Referenceabstract

Log base class: log to console and into log files. More...

#include <log.h>

Inheritance diagram for openm::LogBase:
Collaboration diagram for openm::LogBase:

Public Member Functions

 LogBase (bool i_logToConsole, const char *i_basePath, bool i_logToFile, bool i_useTimeStamp, bool i_usePidStamp, bool i_noMsgTime)
 create log instance.
 
 ~LogBase (void) noexcept
 cleanup log resources
 
const string timeStamp (void) noexcept override
 return timestamp part of log file name: 2012_08_17_16_04_59_148.
 
const bool isEnabled (void) noexcept override
 return true if log to console or to file enabled.
 
const bool isCreateError (void) noexcept override
 error at file create of last log or stamped log file
 
void init (bool i_logToConsole, const char *i_basePath, bool i_logToFile, bool i_useTimeStamp=false, bool i_usePidStamp=false, bool i_noMsgTime=false) noexcept
 re-initialize log file name(s) and other log settings.
 
void setRank (int i_rank, int i_worldSize) noexcept override
 use process rank as log message prefix
 
- Public Member Functions inherited from openm::ILogBase
virtual void logMsg (const char *i_msg, const char *i_extra=NULL) noexcept=0
 log message
 
virtual bool logFormatted (const char *i_format,...) noexcept=0
 log message formatted with vsnprintf()
 

Protected Member Functions

bool doLogMsg (const char *i_msg, const char *i_extra) noexcept
 implement log message: log to console and log files
 
bool logFileCreate (const string &i_path) noexcept
 
virtual bool logToConsole (const chrono::system_clock::time_point &i_msgTime, const char *i_msg, const char *i_extra=nullptr) noexcept=0
 
virtual bool logToFile (bool i_isToStamped, const chrono::system_clock::time_point &i_msgTime, const char *i_msg, const char *i_extra=nullptr) noexcept=0
 
bool writeToLog (ostream &i_ost, const chrono::system_clock::time_point &i_msgTime, const char *i_msg, const char *i_extra=nullptr)
 

Protected Attributes

recursive_mutex theMutex
 
bool isConsoleEnabled
 
bool isLastEnabled
 
bool isLastCreated
 
bool isErrorLastCreate
 
bool isStampedEnabled
 
bool isStampedCreated
 
bool isErrorStampedCreate
 
string tsPart
 
string pidPart
 
string lastPath
 
string stampedPath
 
bool isNoMsgTime
 
string rankPrefix
 
bool isMsgRank
 
char msgBuffer [msgBufferSize+1]
 

Static Protected Attributes

static const size_t msgBufferSize = 32768
 

Detailed Description

Log base class: log to console and into log files.

Constructor & Destructor Documentation

◆ LogBase()

LogBase::LogBase ( bool  i_logToConsole,
const char *  i_basePath,
bool  i_logToFile,
bool  i_useTimeStamp,
bool  i_usePidStamp,
bool  i_noMsgTime 
)

create log instance.

Parameters
[in]i_logToConsoleif true then log to console
[in]i_basePathpath to "last" log file, if NULL or empty "" then no log file
[in]i_logToFileif true then enable log to "last" file
[in]i_useTimeStampif true then use timestamp suffix in "stamped" file name
[in]i_usePidStampif true then use PID suffix in "stamped" file name
[in]i_noMsgTimeif true then not prefix log messages with date-time

Member Function Documentation

◆ init()

void LogBase::init ( bool  i_logToConsole,
const char *  i_basePath,
bool  i_logToFile,
bool  i_useTimeStamp = false,
bool  i_usePidStamp = false,
bool  i_noMsgTime = false 
)
noexcept

re-initialize log file name(s) and other log settings.

Parameters
[in]i_logToConsoleif true then log to console
[in]i_basePathpath to "last" log file, if NULL or empty "" then no log file
[in]i_logToFileif true then enable log to "last" file
[in]i_useTimeStampif true then use timestamp suffix in "stamped" file name
[in]i_usePidStampif true then use PID suffix in "stamped" file name
[in]i_noMsgTimeif true then not prefix log messages with date-time

◆ isCreateError()

const bool LogBase::isCreateError ( void  )
overridevirtualnoexcept

error at file create of last log or stamped log file

Implements openm::ILogBase.

◆ isEnabled()

const bool LogBase::isEnabled ( void  )
overridevirtualnoexcept

return true if log to console or to file enabled.

Implements openm::ILogBase.

◆ setRank()

void LogBase::setRank ( int  i_rank,
int  i_worldSize 
)
overridevirtualnoexcept

use process rank as log message prefix

Implements openm::ILogBase.

◆ timeStamp()

const string LogBase::timeStamp ( void  )
overridevirtualnoexcept

return timestamp part of log file name: 2012_08_17_16_04_59_148.

it is never return empty "" string, even no log enabled or timestamp disabled for log file

Implements openm::ILogBase.


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