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 <boost/shared_ptr.hpp>
34 #include "../Console/LazyDirectory.hh"
35 #include "../Console/Parse.hh"
37 ///////////////////////////////ih.p////////////////////////////////////////
41 namespace console { class DirectoryNode; }
46 struct LogParameters {
47 StreamBase const * stream;
48 AreaBase const * area;
52 static LogParameters defaultParameters();
55 std::ostream & operator<<(std::ostream & os, LogParameters const & pm);
57 void senf_console_parse_argument(console::ParseCommandInfo::TokensRange const & tokens,
60 /** \brief Internal: Target registry */
62 : public senf::singleton<TargetRegistry>
66 VERBOSE = senf::log::VERBOSE::value,
67 NOTICE = senf::log::NOTICE::value,
68 MESSAGE = senf::log::MESSAGE::value,
69 IMPORTANT = senf::log::IMPORTANT::value,
70 CRITICAL = senf::log::CRITICAL::value,
71 FATAL = senf::log::FATAL::value
74 using senf::singleton<TargetRegistry>::instance;
76 void write(StreamBase const & stream, AreaBase const & area, unsigned level,
77 std::string const & msg);
80 bool fallbackRouting();
82 senf::console::ScopedDirectory<> & consoleDir();
84 void dynamicTarget(std::auto_ptr<Target> target);
90 void registerTarget(Target * target, std::string const & name);
91 void unregisterTarget(Target * target);
93 void consoleAreas(std::ostream & os);
94 void consoleStreams(std::ostream & os);
95 void consoleWrite(LogParameters parameters, std::string const & msg);
96 void consoleRemoveTarget(Target * target);
97 boost::shared_ptr<senf::console::DirectoryNode> consoleSelf(std::ostream & os);
99 typedef std::set<Target *> Targets;
102 bool fallbackRouting_;
104 console::LazyDirectory consoleDir_;
106 Targets dynamicTargets_;
108 friend class senf::log::Target;
109 friend class senf::singleton<TargetRegistry>;
112 /** \brief Internal: Write log message */
113 template <class Stream, class Area, class Level>
114 void write(std::string const & msg);
118 // This code takes the routing target template arguments in any order and sorts them
119 // by type (Stream, Area and Level).
121 senf::mpl::rv<0u> RouteParameterCheck_(...);
122 senf::mpl::rv<1u> RouteParameterCheck_(StreamBase *);
123 senf::mpl::rv<2u> RouteParameterCheck_(AreaBase *);
124 template <class T> senf::mpl::rv<3u> RouteParameterCheck_(T*, typename T::SENFLogArea * = 0);
125 senf::mpl::rv<4u> RouteParameterCheck_(LevelBase *);
127 // For g++ 4.0 (at least) we need to provide the fully scoped name for this default value.
128 // no idea why. It works without the scope in 4.1
129 template < class T, class A2, class A1,
130 unsigned type = SENF_MPL_RV( senf::log::detail::RouteParameterCheck_(static_cast<T*>(0)) ) >
131 struct RouteParameters
134 template <class A2, class A1>
135 struct RouteParameters<mpl::nil,A2,A1,0u>
136 : public RouteParameters<A2,A1,mpl::nil>
140 static unsigned const value = NONE::value;
144 struct RouteParameters<mpl::nil,mpl::nil,mpl::nil,0u>
146 typedef mpl::nil Stream;
147 typedef mpl::nil Area;
148 typedef NilLevel Level;
151 template <class T, class A2, class A1>
152 struct RouteParameters<T,A2,A1,1u>
153 : public RouteParameters<A2,A1,mpl::nil>
155 typedef RouteParameters<A2,A1,mpl::nil> base;
156 BOOST_STATIC_ASSERT(( boost::is_same<typename base::Stream, mpl::nil>::value ));
160 template <class T, class A2, class A1>
161 struct RouteParameters<T,A2,A1,2u>
162 : public RouteParameters<A2,A1,mpl::nil>
164 typedef RouteParameters<A2,A1,mpl::nil> base;
165 BOOST_STATIC_ASSERT(( boost::is_same<typename base::Area, mpl::nil>::value ));
169 template <class T, class A2, class A1>
170 struct RouteParameters<T,A2,A1,3u>
171 : public RouteParameters<A2,A1,mpl::nil>
173 typedef RouteParameters<A2,A1,mpl::nil> base;
174 BOOST_STATIC_ASSERT(( boost::is_same<typename base::Area, mpl::nil>::value ));
175 typedef typename T::SENFLogArea Area;
178 template <class T, class A2, class A1>
179 struct RouteParameters<T,A2,A1,4u>
180 : public RouteParameters<A2,A1,mpl::nil>
182 typedef RouteParameters<A2,A1,mpl::nil> base;
183 BOOST_STATIC_ASSERT(( boost::is_same<typename base::Level, NilLevel>::value ));
187 template <class T, class RV>
190 static RV * value() { return & T::instance(); }
194 struct InstanceP<mpl::nil, RV>
196 static RV * value() { return 0; }
203 ///////////////////////////////ih.e////////////////////////////////////////
210 // comment-column: 40
211 // c-file-style: "senf"
212 // indent-tabs-mode: nil
213 // ispell-local-dictionary: "american"
214 // compile-command: "scons -u test"