Logging.h
Go to the documentation of this file.
1 /*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5 *
6 * ArmarX is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * ArmarX is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * @package ArmarXCore::core
19 * @author Kai Welke (welke at kit dot edu)
20 * @author Mirko W├Ąchter 2012 (mirko dot waechter @ kit dot edu)
21 * @date 2010
22 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
23 * GNU General Public License
24 */
25 #pragma once
26 
27 #include <boost/current_function.hpp>
28 
32 
122 #define ARMARX_FUNCTION BOOST_CURRENT_FUNCTION
125 
145 #define ARMARX_LOG_S (*(::armarx::LogSender::createLogSender()->setFile(__FILE__)->setLine(__LINE__)->setFunction(ARMARX_FUNCTION)))
146 
163 #define ARMARX_LOG (*ARMARX_LOG_S.setLocalMinimumLoggingLevel(this->Logging::minimumLoggingLevel)) << this->::armarx::Logging::tag
164 
165 
166 #define _ARMARX_LOG_INTERNAL_S(level) (level < ::armarx::LogSender::GetGlobalMinimumLoggingLevel()) ? _GlobalDummyLogSender : ARMARX_LOG_S << level
167 
168 #define _ARMARX_LOG_INTERNAL_(level) (checkLogLevel(level)) ? _GlobalDummyLogSender : (*loghelper(__FILE__, __LINE__, ARMARX_FUNCTION)) << level
169 
170 
171 
174 #define ARMARX_INFO _ARMARX_LOG_INTERNAL_(::armarx::MessageTypeT::INFO)
175 #define ARMARX_DEBUG _ARMARX_LOG_INTERNAL_(::armarx::MessageTypeT::DEBUG)
178 #define ARMARX_VERBOSE _ARMARX_LOG_INTERNAL_(::armarx::MessageTypeT::VERBOSE)
181 #define ARMARX_IMPORTANT _ARMARX_LOG_INTERNAL_(::armarx::MessageTypeT::IMPORTANT)
184 #define ARMARX_WARNING _ARMARX_LOG_INTERNAL_(::armarx::MessageTypeT::WARN)
187 #define ARMARX_ERROR _ARMARX_LOG_INTERNAL_(::armarx::MessageTypeT::ERROR)
190 #define ARMARX_FATAL _ARMARX_LOG_INTERNAL_(::armarx::MessageTypeT::FATAL)
193 
195 #define ARMARX_INFO_S _ARMARX_LOG_INTERNAL_S(::armarx::MessageTypeT::INFO)
196 #define ARMARX_DEBUG_S _ARMARX_LOG_INTERNAL_S(::armarx::MessageTypeT::DEBUG)
199 #define ARMARX_VERBOSE_S _ARMARX_LOG_INTERNAL_S(::armarx::MessageTypeT::VERBOSE)
201 #define ARMARX_IMPORTANT_S _ARMARX_LOG_INTERNAL_S(::armarx::MessageTypeT::IMPORTANT)
204 #define ARMARX_WARNING_S _ARMARX_LOG_INTERNAL_S(::armarx::MessageTypeT::WARN)
207 #define ARMARX_ERROR_S _ARMARX_LOG_INTERNAL_S(::armarx::MessageTypeT::ERROR)
210 #define ARMARX_FATAL_S _ARMARX_LOG_INTERNAL_S(::armarx::MessageTypeT::FATAL)
213 
214 namespace armarx
215 {
216  class LogSender;
217  using LogSenderPtr = std::shared_ptr<LogSender>;
218 
219  struct SpamFilterData;
220  using SpamFilterDataPtr = std::shared_ptr<SpamFilterData>;
221 
233  {
234  public:
235 
236 
237  Logging();
238  virtual ~Logging();
239  void setTag(const LogTag& tag);
240  void setTag(const std::string& tagName);
246  void setLocalMinimumLoggingLevel(MessageTypeT level);
247  MessageTypeT getEffectiveLoggingLevel() const;
248 
261  SpamFilterDataPtr deactivateSpam(float deactivationDurationSec = 10.0f, const std::string& identifier = "", bool deactivate = true) const;
262 
263  protected:
270  const LogSenderPtr& getLogSender() const;
274  LogSenderPtr loghelper(const char* file, int line, const char* function) const;
275  bool checkLogLevel(MessageTypeT level) const;
276 
277  private:
278  LogSenderPtr logSender;
279 
280  };
281 }
282 
304 #define ARMARX_STREAM_PRINTER ::armarx::detail::StreamPrinterTag::tag * [&](std::ostream& out)
305 
306 armarx::LogSenderPtr loghelper(const char* file, int line, const char* function);
308 armarx::SpamFilterDataPtr deactivateSpam(float deactivationDurationSec = 10.0f, const std::string& identifier = "", bool deactivate = true);
309 inline armarx::SpamFilterDataPtr deactivateSpam(const std::string& identifier, float deactivationDurationSec = 10.0f, bool deactivate = true)
310 {
311  return deactivateSpam(deactivationDurationSec, identifier, deactivate);
312 }
313 
armarx::MessageTypeT
MessageTypeT
Definition: LogSender.h:45
armarx::Logging::minimumLoggingLevel
MessageTypeT minimumLoggingLevel
Definition: Logging.h:272
_GlobalDummyLogSender
const armarx::LogSender _GlobalDummyLogSender
Dummy instance for faster skipped logging (if verbosity level is lower than selected level) - DO NOT ...
Definition: Logging.h:124
armarx::LogSender
Wrapper for the Log IceStorm topic with convenience methods for logging.
Definition: LogSender.h:66
trace.h
loghelper
armarx::LogSenderPtr loghelper(const char *file, int line, const char *function)
Definition: Logging.cpp:131
armarx::Logging::spamFilter
SpamFilterDataPtr spamFilter
Definition: Logging.h:273
StringHelpers.h
armarx::SpamFilterDataPtr
std::shared_ptr< SpamFilterData > SpamFilterDataPtr
Definition: Logging.h:220
armarx::SpamFilterData
Definition: SpamFilterData.h:15
deactivateSpam
armarx::SpamFilterDataPtr deactivateSpam(float deactivationDurationSec=10.0f, const std::string &identifier="", bool deactivate=true)
Definition: Logging.cpp:143
checkLogLevel
bool checkLogLevel(armarx::MessageTypeT level)
Definition: Logging.cpp:136
armarx::Logging
Base Class for all Logging classes.
Definition: Logging.h:232
armarx::LogSenderPtr
std::shared_ptr< LogSender > LogSenderPtr
Typedef of std::shared_ptr for convenience.
Definition: Logging.h:217
LogSender.h
armarx::Logging::tag
LogTag tag
Definition: Logging.h:271
ARMARXCORE_IMPORT_EXPORT
#define ARMARXCORE_IMPORT_EXPORT
Definition: ImportExport.h:38
armarx::LogTag
Definition: LoggingUtil.h:66
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28