4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@berlios.de>
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 \brief Target internal header */
26 #ifndef IH_SENF_Utils_Logger_Target_
27 #define IH_SENF_Utils_Logger_Target_ 1
31 #include <boost/type_traits/is_same.hpp>
32 #include <boost/static_assert.hpp>
33 #include "../Console/LazyDirectory.hh"
35 ///////////////////////////////ih.p////////////////////////////////////////
41 /** \brief Internal: Target registry */
43 : public senf::singleton<TargetRegistry>
47 VERBOSE = senf::log::VERBOSE::value,
48 NOTICE = senf::log::NOTICE::value,
49 MESSAGE = senf::log::MESSAGE::value,
50 IMPORTANT = senf::log::IMPORTANT::value,
51 CRITICAL = senf::log::CRITICAL::value,
52 FATAL = senf::log::FATAL::value
55 using senf::singleton<TargetRegistry>::instance;
57 void write(StreamBase const & stream, AreaBase const & area, unsigned level,
58 std::string const & msg);
61 bool fallbackRouting();
66 void registerTarget(Target * target, std::string const & name);
67 void unregisterTarget(Target * target);
69 void consoleAreas(std::ostream & os);
70 void consoleStreams(std::ostream & os);
71 void consoleWrite(std::string const & stream, std::string const & area, Level level,
72 std::string const & msg);
74 typedef std::set<Target *> Targets;
77 bool fallbackRouting_;
79 console::LazyDirectory consoleDir_;
81 friend class senf::log::Target;
82 friend class senf::singleton<TargetRegistry>;
85 /** \brief Internal: Write log message */
86 template <class Stream, class Area, class Level>
87 void write(std::string const & msg);
91 // This code takes the routing target template arguments in any order and sorts them
92 // by type (Stream, Area and Level).
94 senf::mpl::rv<0u> RouteParameterCheck_(...);
95 senf::mpl::rv<1u> RouteParameterCheck_(StreamBase *);
96 senf::mpl::rv<2u> RouteParameterCheck_(AreaBase *);
97 template <class T> senf::mpl::rv<3u> RouteParameterCheck_(T*, typename T::SENFLogArea * = 0);
98 senf::mpl::rv<4u> RouteParameterCheck_(LevelBase *);
100 // For g++ 4.0 (at least) we need to provide the fully scoped name for this default value.
101 // no idea why. It works without the scope in 4.1
102 template < class T, class A2, class A1,
103 unsigned type = SENF_MPL_RV( senf::log::detail::RouteParameterCheck_(static_cast<T*>(0)) ) >
104 struct RouteParameters
107 template <class A2, class A1>
108 struct RouteParameters<mpl::nil,A2,A1,0u>
109 : public RouteParameters<A2,A1,mpl::nil>
113 static unsigned const value = NONE::value;
117 struct RouteParameters<mpl::nil,mpl::nil,mpl::nil,0u>
119 typedef mpl::nil Stream;
120 typedef mpl::nil Area;
121 typedef NilLevel Level;
124 template <class T, class A2, class A1>
125 struct RouteParameters<T,A2,A1,1u>
126 : public RouteParameters<A2,A1,mpl::nil>
128 typedef RouteParameters<A2,A1,mpl::nil> base;
129 BOOST_STATIC_ASSERT(( boost::is_same<typename base::Stream, mpl::nil>::value ));
133 template <class T, class A2, class A1>
134 struct RouteParameters<T,A2,A1,2u>
135 : public RouteParameters<A2,A1,mpl::nil>
137 typedef RouteParameters<A2,A1,mpl::nil> base;
138 BOOST_STATIC_ASSERT(( boost::is_same<typename base::Area, mpl::nil>::value ));
142 template <class T, class A2, class A1>
143 struct RouteParameters<T,A2,A1,3u>
144 : public RouteParameters<A2,A1,mpl::nil>
146 typedef RouteParameters<A2,A1,mpl::nil> base;
147 BOOST_STATIC_ASSERT(( boost::is_same<typename base::Area, mpl::nil>::value ));
148 typedef typename T::SENFLogArea Area;
151 template <class T, class A2, class A1>
152 struct RouteParameters<T,A2,A1,4u>
153 : public RouteParameters<A2,A1,mpl::nil>
155 typedef RouteParameters<A2,A1,mpl::nil> base;
156 BOOST_STATIC_ASSERT(( boost::is_same<typename base::Level, NilLevel>::value ));
160 template <class T, class RV>
163 static RV * value() { return & T::instance(); }
167 struct InstanceP<mpl::nil, RV>
169 static RV * value() { return 0; }
176 ///////////////////////////////ih.e////////////////////////////////////////
183 // comment-column: 40
184 // c-file-style: "senf"
185 // indent-tabs-mode: nil
186 // ispell-local-dictionary: "american"
187 // compile-command: "scons -u test"