MADARA  3.1.8
Logger.h
Go to the documentation of this file.
1 #ifndef _MADARA_LOGGER_LOGGER_H_
2 #define _MADARA_LOGGER_LOGGER_H_
3 
4 #include "madara/MADARA_export.h"
5 #include "madara/LockType.h"
6 #include <ace/Guard_T.h>
7 #include <vector>
8 #include <string>
9 #include <stdio.h>
11 
20 #define madara_logger_log(logger, level, ...) \
21  if (level <= logger.get_level ()) \
22  logger.log (level, __VA_ARGS__);
23 
32 #define madara_logger_ptr_log(logger, level, ...) \
33  if (logger && level <= logger->get_level ()) \
34  logger->log (level, __VA_ARGS__);
35 
43 #define madara_logger_cond_log_ptrs(conditional, logger_ptr, alt_logger_ptr, level, ...) \
44  if (conditional && logger_ptr && level <= logger_ptr->get_level ()) \
45  logger_ptr->log (level, __VA_ARGS__); \
46  else \
47  alt_logger_ptr->log (level, __VA_ARGS__);
48 
56 #define madara_logger_cond_log(conditional, logger, alt_logger_ptr, level, ...) \
57  if (conditional && level <= logger.get_level ()) \
58  logger.log (level, __VA_ARGS__); \
59  else \
60  alt_logger_ptr->log (level, __VA_ARGS__);
61 
62 namespace madara
63 {
64  namespace logger
65  {
66 
70  enum LogLevels
71  {
74  LOG_ERROR = 1,
76  LOG_MAJOR = 3,
77  LOG_MINOR = 4,
78  LOG_TRACE = 5,
81  };
82 
88  class MADARA_Export Logger
89  {
90  public:
95  Logger (bool log_to_stderr = true);
96 
100  ~Logger ();
101 
107  void log (int level, const char * message, ...);
108 
113  void add_file (const std::string & filename);
114 
118  void add_term (void);
119 
123  void add_syslog (void);
124 
129  void set_level (int level);
130 
135  std::string get_tag (void);
136 
141  void set_tag (const std::string & tag);
142 
147  int get_level (void);
148 
152  void clear (void);
153 
161  void set_timestamp_format (const std::string & format = "%x %X: ");
162 
163  private:
164 
166 
167 
169  typedef std::vector <FILE *> FileVectors;
170 
172  mutable MADARA_LOCK_TYPE mutex_;
173 
175  FileVectors files_;
176 
178  int level_;
179 
182 
185 
188 
191  };
192  }
193 }
194 
195 #include "Logger.inl"
196 
197 #endif // _MADARA_LOGGER_LOGGER_H_
int level_
the maximum detail level for logging
Definition: Logger.h:178
std::string timestamp_format_
the timestamp format. Default is "" for no timestamp
Definition: Logger.h:190
bool term_added_
tracks whether terminal output has been added
Definition: Logger.h:181
Provides knowledge logging services to files and terminals.
Definition: GlobalLogger.h:11
A multi-threaded logger for logging to one or more destinations.
Definition: Logger.h:88
FileVectors files_
list of all log outputs
Definition: Logger.h:175
bool syslog_added_
tracks whether the system log has been added
Definition: Logger.h:184
LogLevels
Logging levels available for MADARA library.
Definition: Logger.h:70
static constexpr struct madara::knowledge::tags::string_t string
std::vector< FILE * > FileVectors
guard for access and changes
Definition: Logger.h:169
MADARA_LOCK_TYPE mutex_
mutex for changes
Definition: Logger.h:172
Copyright (c) 2015 Carnegie Mellon University.
std::string tag_
the tag used for logging to system logs
Definition: Logger.h:187
void log(int level, const char *message)
Logs a simple string message.
Definition: LogMacros.h:224