IBR-DTN  1.0.0
LogFilter.cpp
Go to the documentation of this file.
1 /*
2  * LogFilter.cpp
3  *
4  * Copyright (C) 2014 IBR, TU Braunschweig
5  *
6  * Written-by: Johannes Morgenroth <jm@m-network.de>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21 
22 #include "core/filter/LogFilter.h"
23 
24 namespace dtn
25 {
26  namespace core
27  {
28  const std::string LogFilter::TAG = "BundleFilter";
29 
30  LogFilter::LogFilter(const int debug_level, const std::string &msg)
31  : _level(ibrcommon::LogLevel::debug), _msg(msg), _debug_level(debug_level)
32  {
33  }
34 
35  LogFilter::LogFilter(const ibrcommon::LogLevel::Level level, const std::string &msg)
36  : _level(level), _msg(msg), _debug_level(1)
37  {
38  }
39 
41  {
42  }
43 
44  void LogFilter::log(const FilterContext &context) const throw ()
45  {
46  try {
47  switch (_level)
48  {
49  case ibrcommon::LogLevel::emergency:
50  IBRCOMMON_LOGGER_TAG(TAG, emergency) << _msg << " (" << context.getBundleID().toString() << ")" << IBRCOMMON_LOGGER_ENDL;
51  break;
52 
53  case ibrcommon::LogLevel::alert:
54  IBRCOMMON_LOGGER_TAG(TAG, alert) << _msg << " (" << context.getBundleID().toString() << ")" << IBRCOMMON_LOGGER_ENDL;
55  break;
56 
57  case ibrcommon::LogLevel::critical:
58  IBRCOMMON_LOGGER_TAG(TAG, critical) << _msg << " (" << context.getBundleID().toString() << ")" << IBRCOMMON_LOGGER_ENDL;
59  break;
60 
61  case ibrcommon::LogLevel::error:
62  IBRCOMMON_LOGGER_TAG(TAG, error) << _msg << " (" << context.getBundleID().toString() << ")" << IBRCOMMON_LOGGER_ENDL;
63  break;
64 
65  case ibrcommon::LogLevel::warning:
66  IBRCOMMON_LOGGER_TAG(TAG, warning) << _msg << " (" << context.getBundleID().toString() << ")" << IBRCOMMON_LOGGER_ENDL;
67  break;
68 
69  case ibrcommon::LogLevel::notice:
70  IBRCOMMON_LOGGER_TAG(TAG, notice) << _msg << " (" << context.getBundleID().toString() << ")" << IBRCOMMON_LOGGER_ENDL;
71  break;
72 
73  case ibrcommon::LogLevel::info:
74  IBRCOMMON_LOGGER_TAG(TAG, info) << _msg << " (" << context.getBundleID().toString() << ")" << IBRCOMMON_LOGGER_ENDL;
75  break;
76 
77  case ibrcommon::LogLevel::debug:
78  IBRCOMMON_LOGGER_DEBUG_TAG(TAG, _debug_level) << _msg << " (" << context.getBundleID().toString() << ")" << IBRCOMMON_LOGGER_ENDL;
79  break;
80  }
81  } catch (const FilterException&) {
82 
83  }
84  }
85 
87  {
88  // print logging
89  log(context);
90 
91  // forward call to the next filter or return with the default action
92  return BundleFilter::evaluate(context);
93  }
94 
96  {
97  // print logging
98  log(context);
99 
100  // forward call to the next filter or return with the default action
101  return BundleFilter::filter(context, bundle);
102  }
103  } /* namespace core */
104 } /* namespace dtn */
virtual ACTION filter(const FilterContext &, dtn::data::Bundle &) const
Definition: LogFilter.cpp:95
virtual ACTION evaluate(const FilterContext &) const
Definition: LogFilter.cpp:86
virtual ACTION evaluate(const FilterContext &context) const
virtual ACTION filter(const FilterContext &context, dtn::data::Bundle &bundle) const
const std::string TAG
Definition: dtnoutbox.cpp:62
LogFilter(const ibrcommon::LogLevel::Level level, const std::string &msg)
Definition: LogFilter.cpp:35
virtual ~LogFilter()
Definition: LogFilter.cpp:40