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#include <source_location>
15
16namespace openm
17{
19 struct ILogBase
20 {
21 virtual ~ILogBase(void) noexcept = 0;
22
24 virtual const bool isEnabled(void) noexcept = 0;
25
27 virtual void logMsg(const char * i_msg, const char * i_extra = NULL) noexcept = 0;
28
30 virtual void logFormatted(const char * i_format, ...) noexcept = 0;
31
36 virtual const std::string timeStamp(void) noexcept = 0;
37
39 virtual void setRank(int i_rank, int i_worldSize) noexcept = 0;
40 };
41
43 struct ILog : public virtual ILogBase
44 {
45 virtual ~ILog(void) noexcept = 0;
46
48 virtual void logErr(const std::exception & i_ex, const char * i_msg = NULL) noexcept = 0;
49
51 virtual void logSql(const char * i_sql) noexcept = 0;
52
62 virtual void init(
63 bool i_logToConsole,
64 const char * i_basePath,
65 bool i_logToFile,
66 bool i_useTimeStamp = false,
67 bool i_usePidStamp = false,
68 bool i_noMsgTime = false,
69 bool i_isLogSql = false
70 ) noexcept = 0;
71
73 virtual const std::string lastLogPath(void) noexcept = 0;
74
76 virtual const std::string stampedLogPath(void) noexcept = 0;
77
79 virtual const std::string getMessage(const char * i_sourceMsg) noexcept = 0;
80
82 virtual const std::list<std::string> getLanguages(void) noexcept = 0;
83
85 virtual const std::unordered_map<std::string, std::string> getLanguageMessages(void) noexcept = 0;
86
88 virtual void swapLanguageMessages(const std::list<std::string> & i_langLst, std::unordered_map<std::string, std::string> & io_msgMap) noexcept = 0;
89 };
90
92 struct ITrace : public virtual ILogBase
93 {
94 virtual ~ITrace(void) noexcept = 0;
95
105 virtual void init(
106 bool i_logToConsole,
107 const char * i_basePath,
108 bool i_logToFile,
109 bool i_useTimeStamp = false,
110 bool i_usePidStamp = false,
111 bool i_noMsgTime = false
112 ) noexcept = 0;
113 };
114
116 inline thread_local const char * the_checkpoint_message = "";
117
119 inline thread_local std::source_location the_checkpoint_location;
120}
121
123#define CHECKPOINT(x) { openm::the_checkpoint_location = std::source_location::current(); openm::the_checkpoint_message = x; }
124
126#define LOG_CHECKPOINT \
127 theLog->logFormatted("%s: [%d,%d] %s", \
128 the_checkpoint_message, \
129 the_checkpoint_location.line(), the_checkpoint_location.column(), the_checkpoint_location.file_name());
130
131//
132// OpenM++ common library export
133//
134#ifdef __cplusplus
135 extern "C" {
136#endif
137
139extern openm::ILog * theLog;
140
142extern openm::ITrace * theTrace;
143
144#ifdef __cplusplus
145 }
146#endif
147
149#define LT(sourceMessage) ((theLog->getMessage(sourceMessage)).c_str())
150
152#define NO_LT(sourceMessage) sourceMessage
153
154#endif // OM_H_LOG_H
openM++ namespace
Definition: log.h:32
thread_local std::source_location the_checkpoint_location
checkpoint source code location: file name, line and column
Definition: omLog.h:119
thread_local const char * the_checkpoint_message
checkpoint log message
Definition: omLog.h:116
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:20
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:44
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:93
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.