1 // filter.hpp
2 
3 // Boost Logging library
4 //
5 // Author: John Torjo, www.torjo.com
6 //
7 // Copyright (C) 2007 John Torjo (see www.torjo.com for email)
8 //
9 // Distributed under the Boost Software License, Version 1.0.
10 //    (See accompanying file LICENSE_1_0.txt or copy at
11 //          http://www.boost.org/LICENSE_1_0.txt)
12 //
13 // See http://www.boost.org for updates, documentation, and revision history.
14 // See http://www.torjo.com/log2/ for more details
15 
16 
17 #ifndef JT28092007_filter_HPP_DEFINED
18 #define JT28092007_filter_HPP_DEFINED
19 
20 #include <hpx/util/logging/detail/fwd.hpp>
21 
22 namespace hpx { namespace util {
23 
24 /**
25     @brief Root namespace. All the logging lib is contained in this namespace,
26     or sub-namespaces of this one.
27 */
28 namespace logging {
29 
30 
31 /**
32     @brief Contains filter implementations. A filter tells the logger if
33     it's enabled or not.
34 
35 
36     The %filter namespace contains a few implementations of %filter classes.
37 
38     @c Filter is just a concept. You decide what a @c filter is.
39 
40     The minimalistic filter knows only if <i>it's enabled</i>
41 
42     Filter interface:
43     @code
44     struct some_filter class {
45         // is filter enabled
46         bool is_enabled() ;
47 
48         // ... whatever else you might want
49     };
50     @endcode
51 
52     In your logger, you can use any filter class that's already here,
53     or implement your own.
54 
55     The filters defined by the library are:
56     - filter::always_enabled
57     - filter::always_disabled
58     - filter::debug_enabled
59     - filter::release_enabled
60     - in case you use levels, see level namespace
61 
62 */
63 namespace filter {
64 
65 
66 /**
67     @brief Manages is_enabled/set_enabled in a non-thread-safe way.
68 
69     If you change set_enabled() while program is running, it can take a bit to propagate
70     between threads. Most of the time, this should be acceptable.
71 */
72 struct no_ts {
no_tshpx::util::logging::filter::no_ts73     no_ts() : m_enabled(true) {}
is_enabledhpx::util::logging::filter::no_ts74     bool is_enabled() const { return m_enabled; }
set_enabledhpx::util::logging::filter::no_ts75     void set_enabled(bool enabled) { m_enabled = enabled; }
76 private:
77     bool m_enabled;
78 };
79 
80 
81 /**
82     @brief Filter that is always enabled
83 */
84 struct always_enabled {
is_enabledhpx::util::logging::filter::always_enabled85     static bool is_enabled() { return true; }
86 };
87 
88 
89 /**
90     @brief Filter that is always disabled
91 */
92 struct always_disabled {
is_enabledhpx::util::logging::filter::always_disabled93     static bool is_enabled() { return false; }
94 };
95 
96 
97 /**
98     @brief Filter that is enabled in debug mode
99 */
100 struct debug_enabled {
101 #ifndef NDEBUG
is_enabledhpx::util::logging::filter::debug_enabled102     static bool is_enabled() { return true; }
103 #else
104     static bool is_enabled() { return false; }
105 #endif
106 };
107 
108 
109 /**
110     @brief Filter that is enabled in release mode
111 */
112 struct release_enabled {
113 #ifdef NDEBUG
is_enabledhpx::util::logging::filter::release_enabled114     static bool is_enabled() { return true; }
115 #else
116     static bool is_enabled() { return false; }
117 #endif
118 };
119 
120 } // namespace filter
121 
122 }}}
123 
124 
125 #endif
126