OpenM++ runtime library (libopenm)
omLog.h
Go to the documentation of this file.
1 
5 // Copyright (c) 2013-2015 OpenM++
6 // This code is licensed under the MIT license (see LICENSE.txt for details)
7 
8 #ifndef OM_H_LOG_H
9 #define OM_H_LOG_H
10 
11 #include <string>
12 #include <list>
13 #include <unordered_map>
14 
15 namespace openm
16 {
18  struct ILogBase
19  {
20  virtual ~ILogBase(void) noexcept = 0;
21 
23  virtual const bool isEnabled(void) noexcept = 0;
24 
26  virtual void logMsg(const char * i_msg, const char * i_extra = NULL) noexcept = 0;
27 
29  virtual void logFormatted(const char * i_format, ...) noexcept = 0;
30 
35  virtual const std::string timeStamp(void) noexcept = 0;
36 
38  virtual void setRank(int i_rank, int i_worldSize) noexcept = 0;
39  };
40 
42  struct ILog : public virtual ILogBase
43  {
44  virtual ~ILog(void) noexcept = 0;
45 
47  virtual void logErr(const std::exception & i_ex, const char * i_msg = NULL) noexcept = 0;
48 
50  virtual void logSql(const char * i_sql) noexcept = 0;
51 
61  virtual void init(
62  bool i_logToConsole,
63  const char * i_basePath,
64  bool i_logToFile,
65  bool i_useTimeStamp = false,
66  bool i_usePidStamp = false,
67  bool i_noMsgTime = false,
68  bool i_isLogSql = false
69  ) noexcept = 0;
70 
72  virtual const std::string lastLogPath(void) noexcept = 0;
73 
75  virtual const std::string stampedLogPath(void) noexcept = 0;
76 
78  virtual const std::string getMessage(const char * i_sourceMsg) noexcept = 0;
79 
81  virtual const std::list<std::string> getLanguages(void) noexcept = 0;
82 
84  virtual const std::unordered_map<std::string, std::string> getLanguageMessages(void) noexcept = 0;
85 
87  virtual void swapLanguageMessages(const std::list<std::string> & i_langLst, std::unordered_map<std::string, std::string> & io_msgMap) noexcept = 0;
88  };
89 
91  struct ITrace : public virtual ILogBase
92  {
93  virtual ~ITrace(void) noexcept = 0;
94 
104  virtual void init(
105  bool i_logToConsole,
106  const char * i_basePath,
107  bool i_logToFile,
108  bool i_useTimeStamp = false,
109  bool i_usePidStamp = false,
110  bool i_noMsgTime = false
111  ) noexcept = 0;
112  };
113 }
114 
115 //
116 // OpenM++ common library export
117 //
118 #ifdef __cplusplus
119  extern "C" {
120 #endif
121 
123 extern openm::ILog * theLog;
124 
126 extern openm::ITrace * theTrace;
127 
128 #ifdef __cplusplus
129  }
130 #endif
131 
133 #define LT(sourceMessage) ((theLog->getMessage(sourceMessage)).c_str())
134 
136 #define NO_LT(sourceMessage) sourceMessage
137 
138 #endif // OM_H_LOG_H
openM++ namespace
Definition: log.h:32
openm::ITrace * theTrace
trace log global instance: model debug output to console and log files
Definition: log.cpp:34
openm::ILog * theLog
log global instance: log to console and into log files
Definition: log.cpp:28
base for log public interface
Definition: omLog.h:19
virtual void logMsg(const char *i_msg, const char *i_extra=NULL) noexcept=0
log message
virtual const bool isEnabled(void) noexcept=0
return true if log to console or to file enabled
virtual const std::string timeStamp(void) noexcept=0
return timestamp part of log file name: 2012_08_17_16_04_59_148.
virtual void setRank(int i_rank, int i_worldSize) noexcept=0
use process rank as log message prefix
virtual void logFormatted(const char *i_format,...) noexcept=0
log message formatted with vsnprintf()
log public interface: log to console and into log files
Definition: omLog.h:43
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.
virtual void logErr(const std::exception &i_ex, const char *i_msg=NULL) noexcept=0
log exception
virtual void logSql(const char *i_sql) noexcept=0
log sql query
trace log public interface: model event log to console and into log files
Definition: omLog.h:92
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) noexcept=0
re-initialize log file name(s) and other log settings.