| eRPC Generator (erpcgen) Rev. 1.8.1 NXP Semiconductors

- Main Page
- Classes
- Files

- File List

Logging.h
1 /*
2 * Copyright (c) 2013-14, Freescale Semiconductor, Inc.
3 * Copyright 2016 NXP
4 * All rights reserved.
5 *
6 *
7 * SPDX-License-Identifier: BSD-3-Clause
8 */
9 #if !defined(_Logging_h_)
10 #define _Logging_h_
11
12 #include <cassert>
13 #include <cstdarg>
14 #include <string>
15
46 class Logger
47 {
48 public:
50 enum log_level_t
51 {
52 kUrgent = 0,
53 kError,
54 kWarning,
55 kInfo,
56 kInfo2,
57 kDebug,
58 kDebug2,
59 kInfo1 = kInfo,
60 kDebug1 = kDebug
61 };
62
63 public:
65 Logger()
66 : m_filter(kInfo)
67 , m_level(kInfo)
68 {
69 }
70
72 virtual ~Logger() {}
74
75 inline void setFilterLevel(log_level_t level) { m_filter = level; }
77
79 inline log_level_t getFilterLevel() const { return m_filter; }
80
82 inline void setOutputLevel(log_level_t level) { m_level = level; }
83
85 inline log_level_t getOutputLevel() const { return m_level; }
87
89
90 virtual void log(const char *fmt, ...);
92
94 virtual void log(const std::string &msg) { log(msg.c_str()); }
95
97 virtual void log(log_level_t level, const char *fmt, ...);
98
100 virtual void log(log_level_t level, const std::string &msg) { log(level, msg.c_str()); }
102 virtual void log(const char *fmt, va_list args);
103
105 virtual void log(log_level_t level, const char *fmt, va_list args);
107
108 protected:
109 log_level_t m_filter;
110 log_level_t m_level;
111
112 protected:
114 virtual void _log(Logger::log_level_t level, const char *msg) = 0;
115 };
116
130 class Log
131 {
132 public:
134
135 static inline Logger *getLogger() { return s_logger; }
137
139 static inline void setLogger(Logger *logger) { s_logger = logger; }
141
143
144 static void log(const char *fmt, ...);
146
148 static void log(const std::string &msg);
149
151 static void log(Logger::log_level_t level, const char *fmt, ...);
152
154 static void log(Logger::log_level_t level, const std::string &msg);
156
160
161 static void urgent(const char *fmt, ...);
162 static void error(const char *fmt, ...);
163 static void warning(const char *fmt, ...);
164 static void info(const char *fmt, ...);
165 static void info2(const char *fmt, ...);
166 static void debug(const char *fmt, ...);
167 static void debug2(const char *fmt, ...);
168
169
170 protected:
171 static Logger *s_logger;
172
173 public:
193 class SetOutputLevel
194 {
195 public:
200 SetOutputLevel(Logger::log_level_t level)
201 : m_logger(Log::getLogger())
202 , m_saved(Logger::kInfo)
203 {
204 assert(m_logger);
205 m_saved = m_logger->getOutputLevel();
206 m_logger->setOutputLevel(level);
207 }
208
213 SetOutputLevel(Logger *logger, Logger::log_level_t level)
214 : m_logger(logger)
215 , m_saved(logger->getOutputLevel())
216 {
217 assert(m_logger);
218 m_logger->setOutputLevel(level);
219 }
220
224 ~SetOutputLevel() { m_logger->setOutputLevel(m_saved); }
225
226 protected:
227 Logger *m_logger;
228 Logger::log_level_t m_saved;
229 };
230 };
231
235 class StdoutLogger : public Logger
236 {
237 public:
239 StdoutLogger(Logger::log_level_t stderrLevel = Logger::kWarning)
240 : m_stderrLevel(stderrLevel)
241 {
242 }
243
244 protected:
246 Logger::log_level_t m_stderrLevel;
247
249 virtual void _log(Logger::log_level_t level, const char *msg);
250 };
251
252 #endif // _Logging_h_
Logger::kDebug
For internal reporting.
Definition: Logging.h:57
Logger::getFilterLevel
log_level_t getFilterLevel() const
Returns the current logging filter level.
Definition: Logging.h:79
Logger::kDebug2
Highest log level; verbose debug logging.
Definition: Logging.h:58
Log::SetOutputLevel::SetOutputLevel
SetOutputLevel(Logger::log_level_t level)
Default constructor.
Definition: Logging.h:200
Logger::log_level_t
log_level_t
Logging levels.
Definition: Logging.h:50
Logger
Base logger class.
Definition: Logging.h:46
Logger::getOutputLevel
log_level_t getOutputLevel() const
Returns the current logging output level.
Definition: Logging.h:85
Logger::setOutputLevel
void setOutputLevel(log_level_t level)
Changes the logging output level to level.
Definition: Logging.h:82
Log::s_logger
static Logger * s_logger
The single global logger instance.
Definition: Logging.h:171
Logger::log
virtual void log(const char *fmt,...)
Log with format.
Definition: Logging.cpp:21
Logger::m_filter
log_level_t m_filter
The current logging filter level.
Definition: Logging.h:109
Logger::kInfo1
Alias for kInfo.
Definition: Logging.h:59
Log::SetOutputLevel::SetOutputLevel
SetOutputLevel(Logger *logger, Logger::log_level_t level)
Constructor.
Definition: Logging.h:213
Logger::kInfo2
For verbose status messages.
Definition: Logging.h:56
Logger::_log
virtual void _log(Logger::log_level_t level, const char *msg)=0
The base pure virtual logging function implemented by subclasses.
Log::SetOutputLevel::~SetOutputLevel
~SetOutputLevel()
Destructor.
Definition: Logging.h:224
Log::SetOutputLevel::m_saved
Logger::log_level_t m_saved
Original logging output level.
Definition: Logging.h:228
Logger::log
virtual void log(const std::string &msg)
Log a string object.
Definition: Logging.h:94
StdoutLogger
Simple logger that writes to stdout and stderr.
Definition: Logging.h:235
Logger::log
virtual void log(log_level_t level, const std::string &msg)
Log a string output at a specific output level.
Definition: Logging.h:100
StdoutLogger::m_stderrLevel
Logger::log_level_t m_stderrLevel
Logs at and below this level get sent to stderr.
Definition: Logging.h:246
Logger::kDebug1
Alias for kDebug.
Definition: Logging.h:60
Logger::kError
For fatal error messages.
Definition: Logging.h:53
Logger::kWarning
For non-fatal warning messages.
Definition: Logging.h:54
Log::SetOutputLevel::m_logger
Logger * m_logger
The logger instance we&#39;re controlling.
Definition: Logging.h:227
Logger::kUrgent
The lowest level, for messages that must always be logged.
Definition: Logging.h:52
Log::setLogger
static void setLogger(Logger *logger)
Sets the global logger singleton instance.
Definition: Logging.h:139
Log
Wraps a set of static functions for easy global logging access.
Definition: Logging.h:130
Logger::kInfo
The normal log level, for status messages.
Definition: Logging.h:55
Logger::setFilterLevel
void setFilterLevel(log_level_t level)
Changes the logging level to level.
Definition: Logging.h:76
StdoutLogger::StdoutLogger
StdoutLogger(Logger::log_level_t stderrLevel=Logger::kWarning)
Default constructor.
Definition: Logging.h:239
Log::SetOutputLevel
Utility class to temporarily change the logging output level.
Definition: Logging.h:193
Logger::Logger
Logger()
Default constructor.
Definition: Logging.h:65
Logger::m_level
log_level_t m_level
The current log output level.
Definition: Logging.h:110
Logger::~Logger
virtual ~Logger()
Destructor.
Definition: Logging.h:72