Apama  10.2.0.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 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 320247 2017-11-17 14:42:32Z asd $
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 connectivity {
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("AP_LOG_"+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 }}} // com.softwareag.connectivity
185 
186 // internal implementation included from these files
187 #include <sag_internal/logging.hpp>
188 
189 #endif // _SAG_PLUGIN_LOGGING_HPP_
bool isDebugEnabled() const
Returns true if DEBUG messages will be written to the log.
Definition: sag_plugin_logging.hpp:142
void debug(const std::string &format, ARGS...args) const
Log a message at DEBUG level.
Definition: sag_plugin_logging.hpp:172
bool isInfoEnabled() const
Returns true if INFO messages will be written to the log.
Definition: sag_plugin_logging.hpp:140
Fatal errors.
Definition: sag_connectivity_c.h:81
void warn(const char *format, ARGS...args) const
Log a message at WARN level.
Definition: sag_plugin_logging.hpp:153
Class for writing to the system logger.
Definition: sag_plugin_logging.hpp:72
void error(const char *format, ARGS...args) const
Log a message at ERROR level.
Definition: sag_plugin_logging.hpp:151
Trace.
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:144
bool isErrorEnabled() const
Returns true if ERROR messages will be written to the log.
Definition: sag_plugin_logging.hpp:136
void warn(const std::string &format, ARGS...args) const
Log a message at WARN level.
Definition: sag_plugin_logging.hpp:168
sag_log_level_t level_t
The available log levels.
Definition: sag_plugin_logging.hpp:76
void crit(const std::string &format, ARGS...args) const
Log a message at CRIT level.
Definition: sag_plugin_logging.hpp:162
Debug messages.
Definition: sag_connectivity_c.h:89
Critical log messages.
Definition: sag_connectivity_c.h:79
Definition: sag_connectivity_threading.h:178
void info(const char *format, ARGS...args) const
Log a message at INFO level.
Definition: sag_plugin_logging.hpp:155
sag_log_level_t
Log levels for logging to the host log file.
Definition: sag_connectivity_c.h:76
Non-fatal errors.
Definition: sag_connectivity_c.h:83
void fatal(const char *format, ARGS...args) const
Log a message at FATAL level.
Definition: sag_plugin_logging.hpp:149
void error(const std::string &format, ARGS...args) const
Log a message at ERROR level.
Definition: sag_plugin_logging.hpp:166
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:87
bool isCritEnabled() const
Returns true if CRIT messages will be written to the log.
Definition: sag_plugin_logging.hpp:132
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 trace(const char *format, ARGS...args) const
Log a message at TRACE level.
Definition: sag_plugin_logging.hpp:159
void log(const char *format, ARGS...args) const
Log a message at a given level.
level_t getLevel() const
Returns the current log level.
Definition: sag_plugin_logging.hpp:127
void fatal(const std::string &format, ARGS...args) const
Log a message at FATAL level.
Definition: sag_plugin_logging.hpp:164
void crit(const char *format, ARGS...args) const
Log a message at CRIT level.
Definition: sag_plugin_logging.hpp:147
void debug(const char *format, ARGS...args) const
Log a message at DEBUG level.
Definition: sag_plugin_logging.hpp:157
void info(const std::string &format, ARGS...args) const
Log a message at INFO level.
Definition: sag_plugin_logging.hpp:170
bool isFatalEnabled() const
Returns true if FATAL messages will be written to the log.
Definition: sag_plugin_logging.hpp:134
void trace(const std::string &format, ARGS...args) const
Log a message at TRACE level.
Definition: sag_plugin_logging.hpp:174
bool isWarnEnabled() const
Returns true if WARN messages will be written to the log.
Definition: sag_plugin_logging.hpp:138
Warnings.
Definition: sag_connectivity_c.h:85