Main Page · Modules · All Classes · Class Hierarchy
MCLog.hpp
1 /*
2  * This file is part of the AiBO+ project
3  *
4  * Copyright (C) 2005-2016 Csaba Kertész (csaba.kertesz@gmail.com)
5  *
6  * AiBO+ is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * AiBO+ is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
19  *
20  */
21 
22 #pragma once
23 
24 #include "MCDefs.hpp"
25 #include "MCTypes.hpp"
26 
27 #include <boost/algorithm/string/classification.hpp>
28 
29 #include <string>
30 
31 #include <stdarg.h>
32 
34 
40 #define MC_LOG(...) MCLog::LogMessage(__PRETTY_FUNCTION__, __VA_ARGS__)
42 #define MC_WARNING(...) MCLog::WarningMessage(__PRETTY_FUNCTION__, __VA_ARGS__)
44 #define MC_ERROR(...) MCLog::ErrorMessage(__PRETTY_FUNCTION__, __VA_ARGS__)
46 #define MC_BPRINT(color, ...) MCLog::FormattedMessage(color, true, __VA_ARGS__)
48 #define MC_PRINT(color, ...) MCLog::FormattedMessage(color, false, __VA_ARGS__)
50 #define MC_NPRINT(...) MCLog::FormattedMessage(MCLog::NoColor, false, __VA_ARGS__)
52 
57 class MCLog
58 {
59 public:
61  typedef enum
62  {
63  MinColor = 30,
64  Black = 30,
65  Red = 31,
66  Green = 32,
67  Yellow = 33,
68  Blue = 34,
69  Purple = 35,
70  Cyan = 36,
71  White = 37,
72  NoColor = 38,
74  } ColorType;
75 
77  typedef enum
78  {
79  Normal = 0,
82  } MessageType;
83 
84 protected:
85 
96  static bool IsAnyFilterMatched(const MC::StringList& filters, const std::string& function_name);
97 
98 public:
99 
109  static bool GetDebugStatus(bool global = false);
110 
119  static void SetDebugStatus(bool new_status, bool global = false);
120 
128  static std::string GetDebugFilter();
129 
137  static void SetDebugFilter(const std::string& new_filter);
138 
146  static std::string GetDebugColorFilters();
147 
155  static void SetDebugColorFilters(const std::string& new_color_filters);
156 
167  static void SetCustomHandler(MCLogMessageHandler* handler, bool global = false);
168 
177  static void LogMessage(const char* function, const char* format, ...);
178 
187  static void ErrorMessage(const char* function, const char* format, ...) CLANG_ANALYZER_NORETURN;
188 
197  static void WarningMessage(const char* function, const char* format, ...);
198 
208  static void FormattedMessage(MCLog::ColorType color, bool bold, const char* format, ...);
209 
210 #ifndef __AIBO_BUILD__
211 
220  static QString ConvertFromAnsiToQtMarkup(const QString& orig_str);
221 
231  static QString RemoveMarkup(const QString& orig_str);
232 #endif
233 };
234 
239 {
240 public:
241  // Class destructor
242  virtual ~MCLogMessageHandler() { };
243 
254  virtual void Message(MCLog::MessageType message_type, const char* function,
255  const char* format, va_list arg_list) = 0;
256 };
257 
262 {
263 public:
264 
275  virtual void Message(MCLog::MessageType message_type, const char* function,
276  const char* format, va_list arg_list) override;
277 };
278 
279 #ifndef __AIBO_BUILD__
280 
284 {
285 public:
286 
297  virtual void Message(MCLog::MessageType message_type, const char* function,
298  const char* format, va_list arg_list) override;
299 };
300 #endif
301 
static void ErrorMessage(const char *function, const char *format,...) CLANG_ANALYZER_NORETURN
Print error message with red color.
Definition: MCLog.cpp:229
Log message handler.
Definition: MCLog.hpp:238
ColorType
Definition: MCLog.hpp:61
Basic log functionalities.
Definition: MCLog.hpp:57
static QString RemoveMarkup(const QString &orig_str)
Remove the markup.
Definition: MCLog.cpp:432
static QString ConvertFromAnsiToQtMarkup(const QString &orig_str)
Convert the ANSI codes to Qt markup format.
Definition: MCLog.cpp:374
static void SetCustomHandler(MCLogMessageHandler *handler, bool global=false)
Set custom message handler.
Definition: MCLog.cpp:119
static void SetDebugStatus(bool new_status, bool global=false)
Set debug status.
Definition: MCLog.cpp:79
static std::string GetDebugColorFilters()
Get debug color filter.
Definition: MCLog.cpp:105
static void FormattedMessage(MCLog::ColorType color, bool bold, const char *format,...)
Print normal message.
Definition: MCLog.cpp:321
static std::string GetDebugFilter()
Get debug filter.
Definition: MCLog.cpp:91
Simple class to echo the log messages to the console.
Definition: MCLog.hpp:261
static void LogMessage(const char *function, const char *format,...)
Print log message.
Definition: MCLog.cpp:166
MessageType
Definition: MCLog.hpp:77
Simple class to echo the log messages to the Qt debug console.
Definition: MCLog.hpp:283
static bool GetDebugStatus(bool global=false)
Get debug status.
Definition: MCLog.cpp:68
static void WarningMessage(const char *function, const char *format,...)
Print warning message with yellow color.
Definition: MCLog.cpp:279
static void SetDebugFilter(const std::string &new_filter)
Set debug filter.
Definition: MCLog.cpp:98
static bool IsAnyFilterMatched(const MC::StringList &filters, const std::string &function_name)
Check if any filter matches with the function name.
Definition: MCLog.cpp:128
static void SetDebugColorFilters(const std::string &new_color_filters)
Set debug color filters.
Definition: MCLog.cpp:112