Apama  10.15.1.2
sag_plugin_logging.hpp
Go to the documentation of this file.
1 
2 /*
3  * Title: plugin_logging.hpp
4  * Description: C++ API for logging from plugins
5  * $Copyright (c) 2015-2017, 2019-2020, 2022 Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors.$
6  * Use, reproduction, transfer, publication or disclosure is prohibited except as specifically provided for in your License Agreement with Software AG
7  */
8 
14 #ifndef _SAG_PLUGIN_LOGGING_HPP_
15 #define _SAG_PLUGIN_LOGGING_HPP_
16 
17 #include <string>
18 
19 namespace com {
20 namespace softwareag {
21 namespace _DATAT_INTERNAL_CPP_NAMESPACE {
22 
29 class CacheOwner
30 {
31  friend class CacheForThisThread;
32 public:
34  CacheOwner();
36  ~CacheOwner();
37 private:
39  void *cache;
41  bool inuse;
42 };
43 
52 class CacheForThisThread
53 {
54 public:
56  CacheForThisThread(CacheOwner &owner);
58  ~CacheForThisThread();
59 private:
60  CacheOwner &owner;
61 };
62 
63 
71 class Logger
72 {
73 public:
76 
78  Logger(const std::string &category): category(category), prefix(category), cachedLevel(getLevelImpl()) {}
86  template<level_t LEVEL, typename... ARGS>
87  void log(const char *format, ARGS... args) const;
88 
96  template<typename... ARGS>
97  void log(level_t LEVEL, const char *format, ARGS... args) const;
105  template<level_t LEVEL, typename... ARGS>
106  void log(const std::string &format, ARGS... args) const;
107 
115  template<typename... ARGS>
116  void log(level_t LEVEL, const std::string &format, ARGS... args) const;
117 
118 
120  bool isEnabled(level_t LEVEL) const
121  {
122  return LEVEL <= getLevel();
123  }
124 
126  level_t getLevel() const {
127  return cachedLevel;
128  }
129 
131  bool isCritEnabled() const { return isEnabled(SAG_LOG_CRIT); }
133  bool isFatalEnabled() const { return isEnabled(SAG_LOG_FATAL); }
135  bool isErrorEnabled() const { return isEnabled(SAG_LOG_ERROR); }
137  bool isWarnEnabled() const { return isEnabled(SAG_LOG_WARN); }
139  bool isInfoEnabled() const { return isEnabled(SAG_LOG_INFO); }
141  bool isDebugEnabled() const { return isEnabled(SAG_LOG_DEBUG); }
143  bool isTraceEnabled() const { return isEnabled(SAG_LOG_TRACE); }
144 
146  template<typename... ARGS> void crit(const char *format, ARGS... args) const { log<SAG_LOG_CRIT>(format, args...); }
148  template<typename... ARGS> void fatal(const char *format, ARGS... args) const { log<SAG_LOG_FATAL>(format, args...); }
150  template<typename... ARGS> void error(const char *format, ARGS... args) const { log<SAG_LOG_ERROR>(format, args...); }
152  template<typename... ARGS> void warn(const char *format, ARGS... args) const { log<SAG_LOG_WARN>(format, args...); }
154  template<typename... ARGS> void info(const char *format, ARGS... args) const { log<SAG_LOG_INFO>(format, args...); }
156  template<typename... ARGS> void debug(const char *format, ARGS... args) const { log<SAG_LOG_DEBUG>(format, args...); }
158  template<typename... ARGS> void trace(const char *format, ARGS... args) const { log<SAG_LOG_TRACE>(format, args...); }
159 
161  void crit(const char *str) const { log<SAG_LOG_CRIT>("%s", str); }
163  void fatal(const char *str) const { log<SAG_LOG_FATAL>("%s", str); }
165  void error(const char *str) const { log<SAG_LOG_ERROR>("%s", str); }
167  void warn(const char *str) const { log<SAG_LOG_WARN>("%s", str); }
169  void info(const char *str) const { log<SAG_LOG_INFO>("%s", str); }
171  void debug(const char *str) const { log<SAG_LOG_DEBUG>("%s", str); }
173  void trace(const char *str) const { log<SAG_LOG_TRACE>("%s", str); }
174 
175 
177  void crit(const std::string &str) const { log<SAG_LOG_CRIT>("%s", str.c_str()); }
179  void fatal(const std::string &str) const { log<SAG_LOG_FATAL>("%s", str.c_str()); }
181  void error(const std::string &str) const { log<SAG_LOG_ERROR>("%s", str.c_str()); }
183  void warn(const std::string &str) const { log<SAG_LOG_WARN>("%s", str.c_str()); }
185  void info(const std::string &str) const { log<SAG_LOG_INFO>("%s", str.c_str()); }
187  void debug(const std::string &str) const { log<SAG_LOG_DEBUG>("%s", str.c_str()); }
189  void trace(const std::string &str) const { log<SAG_LOG_TRACE>("%s", str.c_str()); }
190 
192  template<typename... ARGS> void crit(const std::string &format, ARGS... args) const { log<SAG_LOG_CRIT>(format, args...); }
194  template<typename... ARGS> void fatal(const std::string &format, ARGS... args) const { log<SAG_LOG_FATAL>(format, args...); }
196  template<typename... ARGS> void error(const std::string &format, ARGS... args) const { log<SAG_LOG_ERROR>(format, args...); }
198  template<typename... ARGS> void warn(const std::string &format, ARGS... args) const { log<SAG_LOG_WARN>(format, args...); }
200  template<typename... ARGS> void info(const std::string &format, ARGS... args) const { log<SAG_LOG_INFO>(format, args...); }
202  template<typename... ARGS> void debug(const std::string &format, ARGS... args) const { log<SAG_LOG_DEBUG>(format, args...); }
204  template<typename... ARGS> void trace(const std::string &format, ARGS... args) const { log<SAG_LOG_TRACE>(format, args...); }
205  const std::string &getPrefix() const { return prefix; }
206 
207 private:
208  level_t getLevelImpl() const;
209  std::string category;
210  std::string prefix;
211  level_t cachedLevel;
212 };
213 
214 }
215 
216 namespace connectivity { using namespace _DATAT_INTERNAL_CPP_NAMESPACE; }
217 
218 }} // com.softwareag.connectivity
219 
220 // internal implementation included from these files
221 #include <sag_internal/logging.hpp>
222 
223 #endif // _SAG_PLUGIN_LOGGING_HPP_
bool isEnabled(level_t LEVEL) const
Returns true if messages at the given level will be written to the log file.
Definition: sag_plugin_logging.hpp:120
void error(const std::string &str) const
Log a message at ERROR level without any arguments.
Definition: sag_plugin_logging.hpp:181
void warn(const std::string &format, ARGS... args) const
Log a message at WARN level.
Definition: sag_plugin_logging.hpp:198
void crit(const char *str) const
Log a message at CRIT level without any arguments.
Definition: sag_plugin_logging.hpp:161
Fatal errors.
Definition: sag_connectivity_c.h:85
Class for writing to the system logger.
Definition: sag_plugin_logging.hpp:71
bool isCritEnabled() const
Returns true if CRIT messages will be written to the log.
Definition: sag_plugin_logging.hpp:131
void debug(const char *format, ARGS... args) const
Log a message at DEBUG level.
Definition: sag_plugin_logging.hpp:156
Trace.
Definition: sag_connectivity_c.h:95
void error(const std::string &format, ARGS... args) const
Log a message at ERROR level.
Definition: sag_plugin_logging.hpp:196
void error(const char *format, ARGS... args) const
Log a message at ERROR level.
Definition: sag_plugin_logging.hpp:150
sag_log_level_t level_t
The available log levels.
Definition: sag_plugin_logging.hpp:75
bool isWarnEnabled() const
Returns true if WARN messages will be written to the log.
Definition: sag_plugin_logging.hpp:137
void info(const std::string &format, ARGS... args) const
Log a message at INFO level.
Definition: sag_plugin_logging.hpp:200
Debug messages.
Definition: sag_connectivity_c.h:93
Critical log messages.
Definition: sag_connectivity_c.h:83
void trace(const std::string &format, ARGS... args) const
Log a message at TRACE level.
Definition: sag_plugin_logging.hpp:204
level_t getLevel() const
Returns the current log level.
Definition: sag_plugin_logging.hpp:126
sag_log_level_t
Log levels for logging to the host log file.
Definition: sag_connectivity_c.h:80
Non-fatal errors.
Definition: sag_connectivity_c.h:87
void warn(const char *format, ARGS... args) const
Log a message at WARN level.
Definition: sag_plugin_logging.hpp:152
Logger(const std::string &category)
Construct a logger for the given category.
Definition: sag_plugin_logging.hpp:78
Informational messages (default)
Definition: sag_connectivity_c.h:91
bool isTraceEnabled() const
Returns true if TRACE messages will be written to the log.
Definition: sag_plugin_logging.hpp:143
void fatal(const std::string &str) const
Log a message at FATAL level without any arguments.
Definition: sag_plugin_logging.hpp:179
void warn(const std::string &str) const
Log a message at WARN level without any arguments.
Definition: sag_plugin_logging.hpp:183
void info(const char *format, ARGS... args) const
Log a message at INFO level.
Definition: sag_plugin_logging.hpp:154
bool isErrorEnabled() const
Returns true if ERROR messages will be written to the log.
Definition: sag_plugin_logging.hpp:135
void crit(const char *format, ARGS... args) const
Log a message at CRIT level.
Definition: sag_plugin_logging.hpp:146
void debug(const std::string &format, ARGS... args) const
Log a message at DEBUG level.
Definition: sag_plugin_logging.hpp:202
void trace(const std::string &str) const
Log a message at TRACE level without any arguments.
Definition: sag_plugin_logging.hpp:189
void fatal(const std::string &format, ARGS... args) const
Log a message at FATAL level.
Definition: sag_plugin_logging.hpp:194
void error(const char *str) const
Log a message at ERROR level without any arguments.
Definition: sag_plugin_logging.hpp:165
void warn(const char *str) const
Log a message at WARN level without any arguments.
Definition: sag_plugin_logging.hpp:167
bool isFatalEnabled() const
Returns true if FATAL messages will be written to the log.
Definition: sag_plugin_logging.hpp:133
void crit(const std::string &format, ARGS... args) const
Log a message at CRIT level.
Definition: sag_plugin_logging.hpp:192
void info(const std::string &str) const
Log a message at INFO level without any arguments.
Definition: sag_plugin_logging.hpp:185
void debug(const char *str) const
Log a message at DEBUG level without any arguments.
Definition: sag_plugin_logging.hpp:171
void fatal(const char *str) const
Log a message at FATAL level without any arguments.
Definition: sag_plugin_logging.hpp:163
void info(const char *str) const
Log a message at INFO level without any arguments.
Definition: sag_plugin_logging.hpp:169
void crit(const std::string &str) const
Log a message at CRIT level without any arguments.
Definition: sag_plugin_logging.hpp:177
bool isDebugEnabled() const
Returns true if DEBUG messages will be written to the log.
Definition: sag_plugin_logging.hpp:141
void trace(const char *format, ARGS... args) const
Log a message at TRACE level.
Definition: sag_plugin_logging.hpp:158
void debug(const std::string &str) const
Log a message at DEBUG level without any arguments.
Definition: sag_plugin_logging.hpp:187
void trace(const char *str) const
Log a message at TRACE level without any arguments.
Definition: sag_plugin_logging.hpp:173
void fatal(const char *format, ARGS... args) const
Log a message at FATAL level.
Definition: sag_plugin_logging.hpp:148
bool isInfoEnabled() const
Returns true if INFO messages will be written to the log.
Definition: sag_plugin_logging.hpp:139
Warnings.
Definition: sag_connectivity_c.h:89