Logging.cpp
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 ArmarX::core
19 * @author Mirko Waechter ( mirko.waechter at kit dot edu)
20 * @date 2012
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24 
25 #include "Logging.h"
26 #include "SpamFilterData.h"
27 
30 
32 
33 using namespace armarx;
34 
36  :
37  minimumLoggingLevel(MessageTypeT::UNDEFINED),
38  spamFilter(new SpamFilterData()),
39  logSender(new LogSender())
40 {
41 
42 
43  // for (LogSenderPtr myvar_bal = armarx::LogSender::createLogSender(); myvar_bal; myvar_bal.reset())
44  // if (loggingToll)
45  // {
46  // myvarVal << das;
47  // }
48 }
49 
50 
52 {
53 }
54 
55 void Logging::setTag(const LogTag& tag)
56 {
57  this->tag = tag;
58 }
59 
60 void Logging::setTag(const std::string& tagName)
61 {
62  this->tag = LogTag(tagName);
63 }
64 
66 {
67  *logSender << minimumLoggingLevel << "setting logging level to " << LogSender::levelToString(level);
68  logSender->flush();
69  minimumLoggingLevel = level;
70 }
71 
72 SpamFilterDataPtr deactivateSpam(SpamFilterDataPtr const& spamFilter, float deactivationDurationSec, const std::string& identifier, bool deactivate)
73 {
74  if (deactivate)
75  {
76  std::unique_lock lock(*spamFilter->mutex);
77  spamFilter->durationSec = deactivationDurationSec;
78  spamFilter->identifier = identifier;
79 
80  if (spamFilter->filterMap->count(identifier) == 0)
81  {
82  (*spamFilter->filterMap)[identifier].clear();
83  }
84 
85  return spamFilter;
86  }
87 
88 
89  return SpamFilterDataPtr();
90 }
91 
92 SpamFilterDataPtr Logging::deactivateSpam(float deactivationDurationSec, const std::string& identifier, bool deactivate) const
93 {
94  return ::deactivateSpam(spamFilter, deactivationDurationSec, identifier, deactivate);
95 }
96 
98 {
99  return logSender;
100 }
101 
102 LogSenderPtr Logging::loghelper(const char* file, int line, const char* function) const
103 {
104  return LogSender::createLogSender()->setLocalMinimumLoggingLevel(this->Logging::minimumLoggingLevel)->setFile(file)->setLine(line)->setFunction(function)->setTag(this->armarx::Logging::tag);
105 }
106 
108 {
109  return (level < this->getEffectiveLoggingLevel());
110 }
111 
112 
113 
114 
115 
116 
118 {
120  {
122  }
123  else
124  {
125  return minimumLoggingLevel;
126  }
127 }
128 
129 
130 
131 LogSenderPtr loghelper(const char* file, int line, const char* function)
132 {
133  return armarx::LogSender::createLogSender()->setFile(file)->setLine(line)->setFunction(function);
134 }
135 
137 {
139 }
140 
141 
143 SpamFilterDataPtr deactivateSpam(float deactivationDurationSec, const std::string& identifier, bool deactivate)
144 {
145  return deactivateSpam(globalSpamFilter, deactivationDurationSec, identifier, deactivate);
146 }
armarx::MessageTypeT
MessageTypeT
Definition: LogSender.h:45
armarx::Logging::minimumLoggingLevel
MessageTypeT minimumLoggingLevel
Definition: Logging.h:272
armarx::MessageTypeT::UNDEFINED
@ UNDEFINED
armarx::Logging::loghelper
LogSenderPtr loghelper(const char *file, int line, const char *function) const
Definition: Logging.cpp:102
armarx::LogSender
Wrapper for the Log IceStorm topic with convenience methods for logging.
Definition: LogSender.h:66
armarx::LogSender::GetGlobalMinimumLoggingLevel
static MessageTypeT GetGlobalMinimumLoggingLevel()
Definition: LogSender.cpp:688
globalSpamFilter
SpamFilterDataPtr globalSpamFilter(new SpamFilterData())
armarx::Logging::spamFilter
SpamFilterDataPtr spamFilter
Definition: Logging.h:273
StringHelpers.h
checkLogLevel
bool checkLogLevel(MessageTypeT level)
Definition: Logging.cpp:136
deactivateSpam
SpamFilterDataPtr deactivateSpam(SpamFilterDataPtr const &spamFilter, float deactivationDurationSec, const std::string &identifier, bool deactivate)
Definition: Logging.cpp:72
armarx::Logging::getLogSender
const LogSenderPtr & getLogSender() const
Retrieve log sender.
Definition: Logging.cpp:97
armarx::SpamFilterDataPtr
std::shared_ptr< SpamFilterData > SpamFilterDataPtr
Definition: Logging.h:220
armarx::SpamFilterData
Definition: SpamFilterData.h:15
armarx::Logging::setLocalMinimumLoggingLevel
void setLocalMinimumLoggingLevel(MessageTypeT level)
With setLocalMinimumLoggingLevel the minimum verbosity-level of log-messages can be set.
Definition: Logging.cpp:65
armarx::control::hardware_config::tagName
std::string tagName(ConfigTag tag)
Definition: Config.cpp:302
armarx::Logging::getEffectiveLoggingLevel
MessageTypeT getEffectiveLoggingLevel() const
Definition: Logging.cpp:117
SpamFilterData.h
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
armarx::Logging::checkLogLevel
bool checkLogLevel(MessageTypeT level) const
Definition: Logging.cpp:107
armarx::Logging::deactivateSpam
SpamFilterDataPtr deactivateSpam(float deactivationDurationSec=10.0f, const std::string &identifier="", bool deactivate=true) const
disables the logging for the current line for the given amount of seconds.
Definition: Logging.cpp:92
loghelper
LogSenderPtr loghelper(const char *file, int line, const char *function)
Definition: Logging.cpp:131
armarx::Logging::setTag
void setTag(const LogTag &tag)
Definition: Logging.cpp:55
Logging.h
armarx::LogSender::createLogSender
static LogSenderPtr createLogSender()
Definition: LogSender.cpp:86
armarx::LogTag
Definition: LoggingUtil.h:66
armarx::Logging::~Logging
virtual ~Logging()
Definition: Logging.cpp:51
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
Exception.h
armarx::Logging::Logging
Logging()
Definition: Logging.cpp:35
armarx::LogSender::levelToString
static std::string levelToString(MessageTypeT type)
Definition: LogSender.cpp:611