OpenSDN source code
logging.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 #ifndef __LOGGING_H__
6 #define __LOGGING_H__
7 
8 #ifdef __clang__
9 #pragma clang diagnostic push
10 #pragma clang diagnostic ignored "-Wunused-variable"
11 #endif
12 
13 #include <log4cplus/logger.h>
14 #include <log4cplus/loggingmacros.h>
15 #include <log4cplus/initializer.h>
16 
17 #ifdef __clang__
18 #pragma clang diagnostic pop
19 #endif
20 
21 #ifdef __clang__
22 #pragma clang diagnostic push
23 #pragma clang diagnostic ignored "-Wmismatched-tags"
24 #endif
25 
26 #include <boost/units/detail/utility.hpp>
27 
28 #ifdef __clang__
29 #pragma clang diagnostic pop
30 #endif
31 
32 #define TYPE_NAME(_type) boost::units::detail::demangle(typeid(_type).name())
33 
34 #define LOG(_Level, _Msg) \
35  do { \
36  if (LoggingDisabled()) break; \
37  log4cplus::Logger logger = log4cplus::Logger::getRoot(); \
38  LOG4CPLUS_##_Level(logger, _Msg); \
39  } while (0)
40 
43 class Logging {
44 
47  log4cplus::Initializer initializer_;
48 
49 public:
50 
53  Logging();
54 
57  ~Logging();
58 
61  void Init();
62 
66  void Init(const std::string &filename,
67  long maxFileSize,
68  int maxBackupIndex,
69  bool useSyslog,
70  const std::string &syslogFacility,
71  const std::string &ident,
72  log4cplus::LogLevel logLevel);
73 
76  void Init(const std::string &propertyFile);
77 };
78 
79 void LoggingInit();
80 void LoggingInit(const std::string &filename,
81  long maxFileSize,
82  int maxBackupIndex,
83  bool useSyslog,
84  const std::string &syslogFacility,
85  const std::string &ident,
86  log4cplus::LogLevel logLevel);
87 
88 void LoggingInit(const std::string &propertyFile);
89 void SetLoggingLevel(log4cplus::LogLevel logLevel);
90 bool LoggingUseSyslog();
91 
92 //
93 // Disable logging - For testing purposes only
94 //
95 bool LoggingDisabled();
96 void SetLoggingDisabled(bool flag);
97 void SetUseSysLog(bool); // To be used only for testing
98 #endif /* __LOGGING_H__ */
A class providing basic control over logging capabilities in OpenSDN control plane.
Definition: logging.h:43
void Init()
Performs basic initialization of the logging system ( log4cplus).
Definition: logging.cc:31
log4cplus::Initializer initializer_
A log4cplus object to maintain multi- and singlethreaded execution of the logging library.
Definition: logging.h:47
Logging()
Prepares log4cplus library for execution. Uses RAII to free resources after the completion of the pro...
Definition: logging.cc:24
~Logging()
Destroys the object and shutdowns the logging system.
Definition: logging.cc:28
bool LoggingDisabled()
Definition: logging.cc:55
void SetLoggingLevel(log4cplus::LogLevel logLevel)
void SetUseSysLog(bool)
Definition: logging.cc:67
void LoggingInit()
Definition: logging.cc:82
bool LoggingUseSyslog()
Definition: logging.cc:63
void SetLoggingDisabled(bool flag)
Definition: logging.cc:59