OpenM++ runtime library (libopenm)
Loading...
Searching...
No Matches
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 bool 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
42 virtual const bool isCreateError(void) noexcept = 0;
43 };
44
46 struct ILog : public virtual ILogBase
47 {
48 virtual ~ILog(void) noexcept = 0;
49
51 virtual void logErr(const std::exception & i_ex, const char * i_msg = NULL) noexcept = 0;
52
54 virtual void logSql(const char * i_sql) noexcept = 0;
55
65 virtual void init(
66 bool i_logToConsole,
67 const char * i_basePath,
68 bool i_logToFile,
69 bool i_useTimeStamp = false,
70 bool i_usePidStamp = false,
71 bool i_noMsgTime = false,
72 bool i_isLogSql = false
73 ) noexcept = 0;
74
76 virtual const std::string lastLogPath(void) noexcept = 0;
77
79 virtual const std::string stampedLogPath(void) noexcept = 0;
80
82 virtual const std::string getMessage(const char * i_sourceMsg) noexcept = 0;
83
85 virtual const std::list<std::string> getLanguages(void) noexcept = 0;
86
88 virtual const std::unordered_map<std::string, std::string> getLanguageMessages(void) noexcept = 0;
89
91 virtual void swapLanguageMessages(const std::list<std::string> & i_langLst, std::unordered_map<std::string, std::string> & io_msgMap) noexcept = 0;
92 };
93
95 struct ITrace : public virtual ILogBase
96 {
97 virtual ~ITrace(void) noexcept = 0;
98
108 virtual void init(
109 bool i_logToConsole,
110 const char * i_basePath,
111 bool i_logToFile,
112 bool i_useTimeStamp = false,
113 bool i_usePidStamp = false,
114 bool i_noMsgTime = false
115 ) noexcept = 0;
116 };
117
119 inline thread_local const char * the_checkpoint_message = "";
120
122 inline thread_local std::source_location the_checkpoint_location;
123}
124
126#define CHECKPOINT(x) { openm::the_checkpoint_location = std::source_location::current(); openm::the_checkpoint_message = x; }
127
129#define LOG_CHECKPOINT \
130 theLog->logFormatted("%s: [%d,%d] %s", \
131 the_checkpoint_message, \
132 the_checkpoint_location.line(), the_checkpoint_location.column(), the_checkpoint_location.file_name());
133
134//
135// OpenM++ common library export
136//
137#ifdef __cplusplus
138 extern "C" {
139#endif
140
142extern openm::ILog * theLog;
143
145extern openm::ITrace * theTrace;
146
147#ifdef __cplusplus
148 }
149#endif
150
152#define LT(sourceMessage) ((theLog->getMessage(sourceMessage)).c_str())
153
155#define NO_LT(sourceMessage) sourceMessage
156
157#endif // OM_H_LOG_H
ITrace * theTrace
public trace log interface
Definition log.cpp:34
ILog * theLog
public log interface
Definition log.cpp:28
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:122
thread_local const char * the_checkpoint_message
checkpoint log message
Definition omLog.h:119
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 const bool isCreateError(void) noexcept=0
error at file create of last log or stamped log file
virtual bool 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:47
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:96
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.