Galaxis Codebase  1.0.0
Team Galaxis software stack for the Carolo Cup 2023 - ROS2 based software
logging.h
Go to the documentation of this file.
1 /*
2  * Copyright 2012 Stefan Huber
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy
6  * of the License at
7  *
8  * http:www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations
14  * under the License.
15  */
16 
17 #ifndef LOGGING_H
18 #define LOGGING_H
19 
20 #include <string>
21 
22 enum loglevel {
29 };
30 
31 class logging {
32 
33 private:
34  bool lastrelog;
36  bool useColor;
37 
38  unsigned cntErrors;
39  unsigned cntWarnings;
40 
41 public:
42  // Create a new logging
43  logging();
44 
45  // Set new log level
46  void setLevel(loglevel level) {
47  minLevel = level;
48  };
49 
50  // Use color or not?
51  void setUsecolor(bool useColor) {
52  this->useColor = useColor;
53  };
54 
55  // Get number of warnings
56  unsigned getNoWarnings() const {
57  return cntWarnings;
58  };
59 
60  // Get number of errors
61  unsigned getNoErrors() const {
62  return cntErrors;
63  };
64 
65  // Log a new message in well-known printf manner
66  void log(loglevel level, const char* fmt, ...);
67 
68  // Log a new message
69  void log(loglevel level, std::string& str);
70 
71  // Like log(), but overwrite the last line
72  void relog(loglevel level, const char* fmt, ...);
73 
74 private:
75  // Check if we print in this level
76  bool doPrint(loglevel level) const;
77 };
78 #endif
loglevel
loglevel
Definition: logging.h:22
logging::logging
logging()
logging::useColor
bool useColor
Definition: logging.h:36
logging::cntWarnings
unsigned cntWarnings
Definition: logging.h:39
SILENCE
@ SILENCE
Definition: logging.h:28
logging::log
void log(loglevel level, const char *fmt,...)
logging::setLevel
void setLevel(loglevel level)
Definition: logging.h:46
logging::getNoErrors
unsigned getNoErrors() const
Definition: logging.h:61
logging::doPrint
bool doPrint(loglevel level) const
logging::getNoWarnings
unsigned getNoWarnings() const
Definition: logging.h:56
INFO
@ INFO
Definition: logging.h:24
logging::setUsecolor
void setUsecolor(bool useColor)
Definition: logging.h:51
logging::cntErrors
unsigned cntErrors
Definition: logging.h:38
logging::relog
void relog(loglevel level, const char *fmt,...)
ERROR
@ ERROR
Definition: logging.h:27
GOODNEWS
@ GOODNEWS
Definition: logging.h:25
DEBUG
@ DEBUG
Definition: logging.h:23
logging
Definition: logging.h:31
WARNING
@ WARNING
Definition: logging.h:26
logging::minLevel
loglevel minLevel
Definition: logging.h:35
logging::lastrelog
bool lastrelog
Definition: logging.h:34