OpenM++ runtime library (libopenm)
openm::Log Class Reference

log implementation class: log to console and into log files. More...

#include <log.h>

Inheritance diagram for openm::Log:
Collaboration diagram for openm::Log:

Public Member Functions

 Log (bool i_logToConsole=false, const char *i_basePath="openm.log", bool i_logToFile=false, bool i_useTimeStamp=false, bool i_usePidStamp=false)
 create log instance. More...
 
 ~Log (void) noexcept
 cleanup log resources
 
void init (bool i_logToConsole, const char *i_basePath, bool i_logToFile, bool i_useTimeStamp=false, bool i_usePidStamp=false, bool i_noMsgTime=false, bool i_isLogSql=false) noexcept override
 re-initialize log file name(s) and other log settings. More...
 
const string lastLogPath (void) noexcept override
 if log to file enabled return "last" log file path. More...
 
const string stampedLogPath (void) noexcept override
 if log to "stamped" file enabled return "stamped" log file path. More...
 
const string getMessage (const char *i_sourceMsg) noexcept override
 get language-specific message by source non-translated message More...
 
const list< string > getLanguages (void) noexcept override
 get list of language name for the messages, eg: (en-ca, en) More...
 
const unordered_map< string, string > getLanguageMessages (void) noexcept override
 get copy of language-specific messages More...
 
void swapLanguageMessages (const list< string > &i_langLst, unordered_map< string, string > &io_msgMap) noexcept override
 set language-specific messages and update list of languages
 
void logMsg (const char *i_msg, const char *i_extra=NULL) noexcept override
 log message More...
 
void logFormatted (const char *i_format,...) noexcept override
 log message formatted with vsnprintf() More...
 
void logErr (const exception &i_ex, const char *i_msg=nullptr) noexcept override
 log exception More...
 
void logSql (const char *i_sql) noexcept override
 log sql query More...
 
- Public Member Functions inherited from openm::LogBase
 LogBase (bool i_logToConsole, const char *i_basePath, bool i_logToFile, bool i_useTimeStamp, bool i_usePidStamp, bool i_noMsgTime)
 create log instance. More...
 
 ~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. More...
 
const bool isEnabled (void) noexcept override
 return true if log to console or to file enabled. More...
 
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. More...
 
void setRank (int i_rank, int i_worldSize) noexcept override
 use process rank as log message prefix More...
 
virtual const bool isEnabled (void) noexcept=0
 return true if log to console or to file enabled More...
 
virtual void logMsg (const char *i_msg, const char *i_extra=NULL) noexcept=0
 log message More...
 
virtual void logFormatted (const char *i_format,...) noexcept=0
 log message formatted with vsnprintf() More...
 
virtual const std::string timeStamp (void) noexcept=0
 return timestamp part of log file name: 2012_08_17_16_04_59_148. More...
 
virtual void setRank (int i_rank, int i_worldSize) noexcept=0
 use process rank as log message prefix More...
 
- Public Member Functions inherited from openm::ILog
virtual void logErr (const std::exception &i_ex, const char *i_msg=NULL) noexcept=0
 log exception More...
 
virtual void logSql (const char *i_sql) noexcept=0
 log sql query More...
 
virtual void init (bool i_logToConsole, const char *i_basePath, bool i_logToFile, bool i_useTimeStamp=false, bool i_usePidStamp=false, bool i_noMsgTime=false, bool i_isLogSql=false) noexcept=0
 re-initialize log file name(s) and other log settings. More...
 
virtual const std::string lastLogPath (void) noexcept=0
 if log to file enabled return "last" log file path. More...
 
virtual const std::string stampedLogPath (void) noexcept=0
 if log to "stamped" file enabled return "stamped" log file path. More...
 
virtual const std::string getMessage (const char *i_sourceMsg) noexcept=0
 get language-specific message by source non-translated message More...
 
virtual const std::list< std::string > getLanguages (void) noexcept=0
 get list of language name for the messages, eg: (en-ca, en) More...
 
virtual const std::unordered_map< std::string, std::string > getLanguageMessages (void) noexcept=0
 get copy of language-specific messages More...
 
virtual void swapLanguageMessages (const std::list< std::string > &i_langLst, std::unordered_map< std::string, std::string > &io_msgMap) noexcept=0
 set language-specific messages and update list of languages
 

Additional Inherited Members

- Protected Member Functions inherited from openm::LogBase
void 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
 
void writeToLog (ostream &i_ost, const chrono::system_clock::time_point &i_msgTime, const char *i_msg, const char *i_extra=nullptr)
 
- Protected Attributes inherited from openm::LogBase
recursive_mutex theMutex
 
bool isConsoleEnabled
 
bool isLastEnabled
 
bool isLastCreated
 
bool isStampedEnabled
 
bool isStampedCreated
 
string tsPart
 
string pidPart
 
string lastPath
 
string stampedPath
 
bool isNoMsgTime
 
string rankPrefix
 
bool isMsgRank
 
char msgBuffer [msgBufferSize+1]
 
- Static Protected Attributes inherited from openm::LogBase
static const size_t msgBufferSize = 32768
 

Detailed Description

log implementation class: log to console and into log files.

log can be enabled/disabled for 3 independent streams:
console - cout stream
"last run" file - log file with specified name, truncated on every model run
"stamped" file - log file with unique name, created for every model run

"stamped" name produced from "last run" name by adding time-stamp and pid-stamp, i.e.:
modelOne.log => modelOne.2012_08_17_16_04_59_148.1234.log

Constructor & Destructor Documentation

◆ Log()

Log::Log ( bool  i_logToConsole = false,
const char *  i_basePath = "openm.log",
bool  i_logToFile = false,
bool  i_useTimeStamp = false,
bool  i_usePidStamp = false 
)

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

Member Function Documentation

◆ getLanguageMessages()

const unordered_map< string, string > Log::getLanguageMessages ( void  )
overridevirtualnoexcept

get copy of language-specific messages

Implements openm::ILog.

◆ getLanguages()

const list< string > Log::getLanguages ( void  )
overridevirtualnoexcept

get list of language name for the messages, eg: (en-ca, en)

Implements openm::ILog.

◆ getMessage()

const string Log::getMessage ( const char *  i_sourceMsg)
overridevirtualnoexcept

get language-specific message by source non-translated message

Implements openm::ILog.

◆ init()

void Log::init ( bool  i_logToConsole,
const char *  i_basePath,
bool  i_logToFile,
bool  i_useTimeStamp = false,
bool  i_usePidStamp = false,
bool  i_noMsgTime = false,
bool  i_isLogSql = false 
)
overridevirtualnoexcept

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
[in]i_isLogSqlif true then log SQL into log file

Implements openm::ILog.

◆ lastLogPath()

const string Log::lastLogPath ( void  )
overridevirtualnoexcept

if log to file enabled return "last" log file path.

Implements openm::ILog.

◆ logErr()

void Log::logErr ( const exception &  i_ex,
const char *  i_msg = nullptr 
)
overridevirtualnoexcept

log exception

Implements openm::ILog.

◆ logFormatted()

void Log::logFormatted ( const char *  i_format,
  ... 
)
overridevirtualnoexcept

log message formatted with vsnprintf()

Implements openm::ILogBase.

◆ logMsg()

void Log::logMsg ( const char *  i_msg,
const char *  i_extra = NULL 
)
overridevirtualnoexcept

log message

Implements openm::ILogBase.

◆ logSql()

void Log::logSql ( const char *  i_sql)
overridevirtualnoexcept

log sql query

Implements openm::ILog.

◆ stampedLogPath()

const string Log::stampedLogPath ( void  )
overridevirtualnoexcept

if log to "stamped" file enabled return "stamped" log file path.

Implements openm::ILog.


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