Valkka  1.6.1
OpenSource Video Management
logging.h
Go to the documentation of this file.
1 #ifndef LOGGING_HEADER_GUARD
2 #define LOGGING_HEADER_GUARD
3 
4 /*
5  * logging.h : Logging utilities
6  *
7  * (c) Copyright 2017-2024 Sampsa Riikonen
8  *
9  * Authors: Sampsa Riikonen <sampsa.riikonen@iki.fi>
10  *
11  * This file is part of the Valkka library.
12  *
13  * Valkka is free software: you can redistribute it and/or modify
14  * it under the terms of the GNU Lesser General Public License as
15  * published by the Free Software Foundation, either version 3 of the
16  * License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU Lesser General Public License for more details.
22  *
23  * You should have received a copy of the GNU Lesser General Public License
24  * along with this program. If not, see <https://www.gnu.org/licenses/>
25  *
26  */
27 
38 #include <stdlib.h>
39 #include <iostream>
40 
41 
42 namespace LogLevel {
43  const static int quiet =-3;
44  const static int fatal =-2;
45  const static int silent=-1;
46  const static int normal=0;
47  const static int debug =2;
48  const static int crazy =3;
49 }; //
50 
51 
63 struct Logger
64 {
65  // Logger(int log_level=LogLevel::normal) : log_level(log_level), current_level(log_level), special_level(0), current_special_level(-1) {};
66  Logger(int log_level=LogLevel::normal);
67 
68  /*
69  template <typename T> // T refers to *any* type
70  Logger& operator<<(const T& x);
71  */
72 
73  template <typename T> // T refers to *any* type
74  Logger& operator<<(const T& x)
75  {
76  // std::cout << "current_level, log_level=" << current_level << " " << log_level << std::endl;
77  // if (current_level<=log_level or current_special_level==special_level) {
78  if (current_level<=log_level) { // current_level is defined at each print .. so, print all messages that are <= the target level
79  std::cout << x;
80  // std::cout << x << " (c:"<<current_level<<"/ l:"<<log_level<<") "; // debugging the debugging.. eh
81  }
82  return *this;
83  }
84 
85  int log_level;
86  int current_level;
87  // int special_level;
88  // int current_special_level;
89 
90  void setLevel(int level);
91 
92  Logger& log(int level);
93 
94  /*
95  void setSpecialLevel(int level) { // evokes logs tagged with a special marker
96  special_level=level;
97  }
98 
99  Logger& slog(int level) {
100  current_special_level=level;
101  return *this;
102  }
103  */
104 
105  /* // here could write exceptions to any type ..
106  Logger& operator<<(const int& x)
107  {
108  std::cout << " inteteger: ";
109  std::cout << x;
110  return *this;
111  }
112  */
113 
114  /*
115  Logger& operator<<(const LogLevel& x) // nopes.. not like this
116  {
117  // std::cout << " stopping log ";
118  current_level=x;
119  return *this;
120  }
121  */
122 
123  // function that takes a custom stream, and returns it
124  typedef Logger& (*LoggerManipulator)(Logger&); // so.. we create a function type here, because of the brackets () .. a function that eats Logger
125 
126  // take in a function with the custom signature
127  Logger& operator<<(LoggerManipulator manip); // .. when we encounter that function that eats Logger
128 
129  // define the custom endl for this stream.
130  // note how it matches the `LoggerManipulator`
131  // function signature
132  static Logger& endl(Logger& stream);
133 
134  // this is the type of std::cout
135  typedef std::basic_ostream<char, std::char_traits<char> > CoutType;
136 
137  // this is the function signature of std::endl
138  typedef CoutType& (*StandardEndLine)(CoutType&);
139 
140  // define an operator<< to take in std::endl
141  Logger& operator<<(StandardEndLine manip);
142 
143 };
144 
145 
153 extern Logger framelogger;
154 extern Logger filterlogger;
155 extern Logger livelogger;
156 extern Logger threadlogger;
157 extern Logger livethreadlogger;
158 extern Logger avthreadlogger;
159 extern Logger decoderlogger;
160 extern Logger fifologger;
161 extern Logger opengllogger;
162 extern Logger filelogger;
163 extern Logger filethreadlogger;
164 extern Logger usblogger;
165 extern Logger valkkafslogger;
166 
167 extern void setLogLevel_framelogger(int level); // <pyapi>
168 extern void setLogLevel_filterlogger(int level); // <pyapi>
169 extern void setLogLevel_livelogger(int level); // <pyapi>
170 extern void setLogLevel_threadlogger(int level); // <pyapi>
171 extern void setLogLevel_livethreadlogger(int level); // <pyapi>
172 extern void setLogLevel_avthreadlogger(int level); // <pyapi>
173 extern void setLogLevel_decoderlogger(int level); // <pyapi>
174 extern void setLogLevel_fifologger(int level); // <pyapi>
175 extern void setLogLevel_opengllogger(int level); // <pyapi>
176 extern void setLogLevel_filelogger(int level); // <pyapi>
177 extern void setLogLevel_filethreadlogger(int level); // <pyapi>
178 extern void setLogLevel_usblogger(int level); // <pyapi>
179 extern void setLogLevel_valkkafslogger(int level); // <pyapi>
180 
181 extern void crazy_log_all(); // <pyapi>
182 extern void debug_log_all(); // <pyapi>
183 extern void normal_log_all(); // <pyapi>
184 extern void fatal_log_all(); // <pyapi>
185 extern void quiet_log_all(); // <pyapi>
186 
187 #endif
Logger framelogger
Singleton: https://en.wikipedia.org/wiki/Singleton_pattern https://stackoverflow.com/questions/297822...
Definition: logging.cpp:93
Logging facility.
Definition: logging.h:64