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
32 #include <boost/type_traits/is_same.hpp>
33 #include <boost/static_assert.hpp>
34 #include <boost/shared_ptr.hpp>
35 #include <senf/Utils/singleton.hh>
36 #include <senf/Utils/mpl.hh>
37 #include <senf/Utils/Console/LazyDirectory.hh>
38 #include <senf/Utils/Console/Parse.hh>
40 //-/////////////////////////////////////////////////////////////////////////////////////////////////
44 namespace console { class DirectoryNode; }
49 struct LogParameters {
50 StreamBase const * stream;
51 AreaBase const * area;
55 static LogParameters defaultParameters();
58 std::ostream & operator<<(std::ostream & os, LogParameters const & pm);
60 void senf_console_parse_argument(console::ParseCommandInfo::TokensRange const & tokens,
63 /** \brief Internal: Target registry */
65 : public senf::singleton<TargetRegistry>
69 VERBOSE = senf::log::VERBOSE::value,
70 NOTICE = senf::log::NOTICE::value,
71 MESSAGE = senf::log::MESSAGE::value,
72 IMPORTANT = senf::log::IMPORTANT::value,
73 CRITICAL = senf::log::CRITICAL::value,
74 FATAL = senf::log::FATAL::value
77 using senf::singleton<TargetRegistry>::instance;
79 void write(StreamBase const & stream, AreaBase const & area, unsigned level,
80 std::string const & msg);
83 bool fallbackRouting();
85 senf::console::ScopedDirectory<> & consoleDir();
87 void dynamicTarget(std::auto_ptr<Target> target);
93 void registerTarget(Target * target, std::string const & name);
94 void unregisterTarget(Target * target);
96 void consoleAreas(std::ostream & os);
97 void consoleStreams(std::ostream & os);
98 void consoleWrite(LogParameters parameters, std::string const & msg);
99 void consoleRemoveTarget(Target * target);
100 boost::shared_ptr<senf::console::DirectoryNode> consoleSelf(std::ostream & os);
102 typedef std::set<Target *> Targets;
105 bool fallbackRouting_;
107 console::LazyDirectory consoleDir_;
109 Targets dynamicTargets_;
111 friend class senf::log::Target;
112 friend class senf::singleton<TargetRegistry>;
115 /** \brief Internal: Write log message */
116 template <class Stream, class Area, class Level>
117 void write(std::string const & msg);
121 // This code takes the routing target template arguments in any order and sorts them
122 // by type (Stream, Area and Level).
124 senf::mpl::rv<0u> RouteParameterCheck_(...);
125 senf::mpl::rv<1u> RouteParameterCheck_(StreamBase *);
126 senf::mpl::rv<2u> RouteParameterCheck_(AreaBase *);
127 template <class T> senf::mpl::rv<3u> RouteParameterCheck_(T*, typename T::SENFLogArea * = 0);
128 senf::mpl::rv<4u> RouteParameterCheck_(LevelBase *);
130 // For g++ 4.0 (at least) we need to provide the fully scoped name for this default value.
131 // no idea why. It works without the scope in 4.1
132 template < class T, class A2, class A1,
133 unsigned type = SENF_MPL_RV( senf::log::detail::RouteParameterCheck_(static_cast<T*>(0)) ) >
134 struct RouteParameters
137 template <class A2, class A1>
138 struct RouteParameters<mpl::nil,A2,A1,0u>
139 : public RouteParameters<A2,A1,mpl::nil>
143 static unsigned const value = NONE::value;
147 struct RouteParameters<mpl::nil,mpl::nil,mpl::nil,0u>
149 typedef mpl::nil Stream;
150 typedef mpl::nil Area;
151 typedef NilLevel Level;
154 template <class T, class A2, class A1>
155 struct RouteParameters<T,A2,A1,1u>
156 : public RouteParameters<A2,A1,mpl::nil>
158 typedef RouteParameters<A2,A1,mpl::nil> base;
159 BOOST_STATIC_ASSERT(( boost::is_same<typename base::Stream, mpl::nil>::value ));
163 template <class T, class A2, class A1>
164 struct RouteParameters<T,A2,A1,2u>
165 : public RouteParameters<A2,A1,mpl::nil>
167 typedef RouteParameters<A2,A1,mpl::nil> base;
168 BOOST_STATIC_ASSERT(( boost::is_same<typename base::Area, mpl::nil>::value ));
172 template <class T, class A2, class A1>
173 struct RouteParameters<T,A2,A1,3u>
174 : public RouteParameters<A2,A1,mpl::nil>
176 typedef RouteParameters<A2,A1,mpl::nil> base;
177 BOOST_STATIC_ASSERT(( boost::is_same<typename base::Area, mpl::nil>::value ));
178 typedef typename T::SENFLogArea Area;
181 template <class T, class A2, class A1>
182 struct RouteParameters<T,A2,A1,4u>
183 : public RouteParameters<A2,A1,mpl::nil>
185 typedef RouteParameters<A2,A1,mpl::nil> base;
186 BOOST_STATIC_ASSERT(( boost::is_same<typename base::Level, NilLevel>::value ));
190 template <class T, class RV>
193 static RV * value() { return & T::instance(); }
197 struct InstanceP<mpl::nil, RV>
199 static RV * value() { return 0; }
206 //-/////////////////////////////////////////////////////////////////////////////////////////////////
213 // comment-column: 40
214 // c-file-style: "senf"
215 // indent-tabs-mode: nil
216 // ispell-local-dictionary: "american"
217 // compile-command: "scons -u test"