Revised OpenFlow Library  v0.6.0dev
 All Classes Files Functions Variables Friends Groups Pages
logging.h
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4 
5 #ifndef LOGGING_H_
6 #define LOGGING_H_ 1
7 
8 #include <iostream>
9 #include <fstream>
10 #include <iomanip>
11 #include <string>
12 
13 namespace rofl
14 {
15 
16 class logging
17 {
18 public:
19 
20  static std::filebuf devnull;
21  static std::filebuf logfile;
22  static std::ostream emerg;
23  static std::ostream alert;
24  static std::ostream crit;
25  static std::ostream error;
26  static std::ostream warn;
27  static std::ostream notice;
28  static std::ostream info;
29  static std::ostream debug;
30  static std::ostream debug2;
31  static std::ostream debug3;
32  static std::ostream trace;
33  static std::streamsize width;
34 
35 public:
36 
37 
38  /*
39  * Logging levels. It is recommended to use these identifiers
40  * for code portability while setting debug level
41  */
42  static const unsigned int EMERG = 0;
43  static const unsigned int ALERT = 1;
44  static const unsigned int CRIT = 2;
45  static const unsigned int ERROR = 3;
46  static const unsigned int WARN = 4;
47  static const unsigned int NOTICE = 5;
48  static const unsigned int INFO = 6;
49  static const unsigned int DBG = 7; //Prevent DEBUG macro expansion
50  static const unsigned int DBG2 = 8; //Prevent DEBUG macro expansion
51  static const unsigned int DBG3 = 9; //Prevent DEBUG macro expansion
52  static const unsigned int TRACE = 10;
53 
57  static void
58  init();
59 
63  static void
64  close();
65 
70  static void
72  unsigned int debug_level);
73 };
74 
75 
76 class indent
77 {
78  static unsigned int width;
79  unsigned int my_width;
80 public:
81  indent(unsigned int my_width = 0) :
82  my_width(my_width) {
83  indent::width += my_width;
84  };
85  virtual ~indent() {
86  indent::width = (indent::width >= my_width) ? (indent::width - my_width) : 0;
87  };
88  static void inc(unsigned int width) {
89  indent::width += width;
90  };
91  static void dec(unsigned int width) {
92  indent::width = (indent::width >= width) ? (indent::width - width) : 0;
93  };
94  static void null() {
95  indent::width = 0;
96  };
97  friend std::ostream&
98  operator<< (std::ostream& os, indent const& i) {
99  if (indent::width) {
100  os << std::setw(indent::width) << " " << std::setw(0);
101  }
102  return os;
103  };
104 };
105 
106 
107 }; // end of namespace
108 
109 #endif /* LOGGING_H_ */
static void init()
Definition: logging.cc:35
Definition: logging.h:16
static void set_debug_level(unsigned int debug_level)
Definition: logging.cc:54
Definition: logging.h:76
static void close()
Definition: logging.cc:44