Apama  10.11.3.3
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 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  * @Version: $Id: sag_plugin_logging.hpp 366779 2020-02-05 10:42:04Z matj $
8  */
9 
15 #ifndef _SAG_PLUGIN_LOGGING_HPP_
16 #define _SAG_PLUGIN_LOGGING_HPP_
17 
18 #include <string>
19 
20 namespace com {
21 namespace softwareag {
22 namespace _DATAT_INTERNAL_CPP_NAMESPACE {
23 
30 class CacheOwner
31 {
32  friend class CacheForThisThread;
33 public:
35  CacheOwner();
37  ~CacheOwner();
38 private:
40  void *cache;
42  bool inuse;
43 };
44 
53 class CacheForThisThread
54 {
55 public:
57  CacheForThisThread(CacheOwner &owner);
59  ~CacheForThisThread();
60 private:
61  CacheOwner &owner;
62 };
63 
64 
72 class Logger
73 {
74 public:
77 
79  Logger(const std::string &category): category(category), prefix(category), cachedLevel(getLevelImpl()) {}
87  template<level_t LEVEL, typename... ARGS>
88  void log(const char *format, ARGS... args) const;
89 
97  template<typename... ARGS>
98  void log(level_t LEVEL, const char *format, ARGS... args) const;
106  template<level_t LEVEL, typename... ARGS>
107  void log(const std::string &format, ARGS... args) const;
108 
116  template<typename... ARGS>
117  void log(level_t LEVEL, const std::string &format, ARGS... args) const;
118 
119 
121  bool isEnabled(level_t LEVEL) const
122  {
123  return LEVEL <= getLevel();
124  }
125 
127  level_t getLevel() const {
128  return cachedLevel;
129  }
130 
132  bool isCritEnabled() const { return isEnabled(SAG_LOG_CRIT); }
134  bool isFatalEnabled() const { return isEnabled(SAG_LOG_FATAL); }
136  bool isErrorEnabled() const { return isEnabled(SAG_LOG_ERROR); }
138  bool isWarnEnabled() const { return isEnabled(SAG_LOG_WARN); }
140  bool isInfoEnabled() const { return isEnabled(SAG_LOG_INFO); }
142  bool isDebugEnabled() const { return isEnabled(SAG_LOG_DEBUG); }
144  bool isTraceEnabled() const { return isEnabled(SAG_LOG_TRACE); }
145 
147  template<typename... ARGS> void crit(const char *format, ARGS... args) const { log<SAG_LOG_CRIT>(format, args...); }
149  template<typename... ARGS> void fatal(const char *format, ARGS... args) const { log<SAG_LOG_FATAL>(format, args...); }
151  template<typename... ARGS> void error(const char *format, ARGS... args) const { log<SAG_LOG_ERROR>(format, args...); }
153  template<typename... ARGS> void warn(const char *format, ARGS... args) const { log<SAG_LOG_WARN>(format, args...); }
155  template<typename... ARGS> void info(const char *format, ARGS... args) const { log<SAG_LOG_INFO>(format, args...); }
157  template<typename... ARGS> void debug(const char *format, ARGS... args) const { log<SAG_LOG_DEBUG>(format, args...); }
159  template<typename... ARGS> void trace(const char *format, ARGS... args) const { log<SAG_LOG_TRACE>(format, args...); }
160 
162  template<typename... ARGS> void crit(const std::string &format, ARGS... args) const { log<SAG_LOG_CRIT>(format, args...); }
164  template<typename... ARGS> void fatal(const std::string &format, ARGS... args) const { log<SAG_LOG_FATAL>(format, args...); }
166  template<typename... ARGS> void error(const std::string &format, ARGS... args) const { log<SAG_LOG_ERROR>(format, args...); }
168  template<typename... ARGS> void warn(const std::string &format, ARGS... args) const { log<SAG_LOG_WARN>(format, args...); }
170  template<typename... ARGS> void info(const std::string &format, ARGS... args) const { log<SAG_LOG_INFO>(format, args...); }
172  template<typename... ARGS> void debug(const std::string &format, ARGS... args) const { log<SAG_LOG_DEBUG>(format, args...); }
174  template<typename... ARGS> void trace(const std::string &format, ARGS... args) const { log<SAG_LOG_TRACE>(format, args...); }
175  const std::string &getPrefix() const { return prefix; }
176 
177 private:
178  level_t getLevelImpl() const;
179  std::string category;
180  std::string prefix;
181  level_t cachedLevel;
182 };
183 
184 }
185 
186 namespace connectivity { using namespace _DATAT_INTERNAL_CPP_NAMESPACE; }
187 
188 }} // com.softwareag.connectivity
189 
190 // internal implementation included from these files
191 #include <sag_internal/logging.hpp>
192 
193 #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:121
void warn(const std::string &format, ARGS... args) const
Log a message at WARN level.
Definition: sag_plugin_logging.hpp:168
Fatal errors.
Definition: sag_connectivity_c.h:86
Class for writing to the system logger.
Definition: sag_plugin_logging.hpp:72
bool isCritEnabled() const
Returns true if CRIT messages will be written to the log.
Definition: sag_plugin_logging.hpp:132
void debug(const char *format, ARGS... args) const
Log a message at DEBUG level.
Definition: sag_plugin_logging.hpp:157
Trace.
Definition: sag_connectivity_c.h:96
void error(const std::string &format, ARGS... args) const
Log a message at ERROR level.
Definition: sag_plugin_logging.hpp:166
void error(const char *format, ARGS... args) const
Log a message at ERROR level.
Definition: sag_plugin_logging.hpp:151
sag_log_level_t level_t
The available log levels.
Definition: sag_plugin_logging.hpp:76
bool isWarnEnabled() const
Returns true if WARN messages will be written to the log.
Definition: sag_plugin_logging.hpp:138
void info(const std::string &format, ARGS... args) const
Log a message at INFO level.
Definition: sag_plugin_logging.hpp:170
Debug messages.
Definition: sag_connectivity_c.h:94
Critical log messages.
Definition: sag_connectivity_c.h:84
void trace(const std::string &format, ARGS... args) const
Log a message at TRACE level.
Definition: sag_plugin_logging.hpp:174
level_t getLevel() const
Returns the current log level.
Definition: sag_plugin_logging.hpp:127
sag_log_level_t
Log levels for logging to the host log file.
Definition: sag_connectivity_c.h:81
Non-fatal errors.
Definition: sag_connectivity_c.h:88
void warn(const char *format, ARGS... args) const
Log a message at WARN level.
Definition: sag_plugin_logging.hpp:153
Logger(const std::string &category)
Construct a logger for the given category.
Definition: sag_plugin_logging.hpp:79
Informational messages (default)
Definition: sag_connectivity_c.h:92
bool isTraceEnabled() const
Returns true if TRACE messages will be written to the log.
Definition: sag_plugin_logging.hpp:144
void info(const char *format, ARGS... args) const
Log a message at INFO level.
Definition: sag_plugin_logging.hpp:155
bool isErrorEnabled() const
Returns true if ERROR messages will be written to the log.
Definition: sag_plugin_logging.hpp:136
void crit(const char *format, ARGS... args) const
Log a message at CRIT level.
Definition: sag_plugin_logging.hpp:147
void debug(const std::string &format, ARGS... args) const
Log a message at DEBUG level.
Definition: sag_plugin_logging.hpp:172
void fatal(const std::string &format, ARGS... args) const
Log a message at FATAL level.
Definition: sag_plugin_logging.hpp:164
bool isFatalEnabled() const
Returns true if FATAL messages will be written to the log.
Definition: sag_plugin_logging.hpp:134
void crit(const std::string &format, ARGS... args) const
Log a message at CRIT level.
Definition: sag_plugin_logging.hpp:162
bool isDebugEnabled() const
Returns true if DEBUG messages will be written to the log.
Definition: sag_plugin_logging.hpp:142
void trace(const char *format, ARGS... args) const
Log a message at TRACE level.
Definition: sag_plugin_logging.hpp:159
void fatal(const char *format, ARGS... args) const
Log a message at FATAL level.
Definition: sag_plugin_logging.hpp:149
bool isInfoEnabled() const
Returns true if INFO messages will be written to the log.
Definition: sag_plugin_logging.hpp:140
Warnings.
Definition: sag_connectivity_c.h:90