// $Id$ // // Copyright (C) 2007 // Fraunhofer Institute for Open Communication Systems (FOKUS) // // The contents of this file are subject to the Fraunhofer FOKUS Public License // Version 1.0 (the "License"); you may not use this file except in compliance // with the License. You may obtain a copy of the License at // http://senf.berlios.de/license.html // // The Fraunhofer FOKUS Public License Version 1.0 is based on, // but modifies the Mozilla Public License Version 1.1. // See the full license text for the amendments. // // Software distributed under the License is distributed on an "AS IS" basis, // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License // for the specific language governing rights and limitations under the License. // // The Original Code is Fraunhofer FOKUS code. // // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. // (registered association), Hansastraße 27 c, 80686 Munich, Germany. // All Rights Reserved. // // Contributor(s): // Stefan Bund /** \file \brief Target internal header */ #ifndef IH_SENF_Utils_Logger_Target_ #define IH_SENF_Utils_Logger_Target_ 1 // Custom includes #include #include #include #include #include #include #include #include #include //-///////////////////////////////////////////////////////////////////////////////////////////////// namespace senf { namespace console { class DirectoryNode; } namespace log { namespace detail { struct LogParameters { StreamBase const * stream; AreaBase const * area; unsigned level; void clear(); void setDefaults(); static LogParameters defaultParameters(); }; std::ostream & operator<<(std::ostream & os, LogParameters const & pm); void senf_console_parse_argument(console::ParseCommandInfo::TokensRange const & tokens, LogParameters & out); /** \brief Internal: Target registry */ class TargetRegistry : public senf::singleton { public: enum Level { VERBOSE = senf::log::VERBOSE::value, NOTICE = senf::log::NOTICE::value, MESSAGE = senf::log::MESSAGE::value, IMPORTANT = senf::log::IMPORTANT::value, CRITICAL = senf::log::CRITICAL::value, FATAL = senf::log::FATAL::value }; using senf::singleton::instance; void write(StreamBase const & stream, AreaBase const & area, unsigned level, std::string const & msg); void routed(); bool fallbackRouting(); senf::console::ScopedDirectory<> & consoleDir(); void dynamicTarget(std::auto_ptr target); private: TargetRegistry(); ~TargetRegistry(); void registerTarget(Target * target, std::string const & name); void unregisterTarget(Target * target); void consoleAreas(std::ostream & os); void consoleStreams(std::ostream & os); void consoleWrite(LogParameters parameters, std::string const & msg); void consoleRemoveTarget(Target * target); boost::shared_ptr consoleSelf(std::ostream & os); typedef std::set Targets; Targets targets_; bool fallbackRouting_; console::LazyDirectory consoleDir_; Targets dynamicTargets_; friend class senf::log::Target; friend class senf::singleton; }; /** \brief Internal: Write log message */ template void write(std::string const & msg); #ifndef DOXYGEN // This code takes the routing target template arguments in any order and sorts them // by type (Stream, Area and Level). senf::mpl::rv<0u> RouteParameterCheck_(...); senf::mpl::rv<1u> RouteParameterCheck_(StreamBase *); senf::mpl::rv<2u> RouteParameterCheck_(AreaBase *); template senf::mpl::rv<3u> RouteParameterCheck_(T*, typename T::SENFLogArea * = 0); senf::mpl::rv<4u> RouteParameterCheck_(LevelBase *); // For g++ 4.0 (at least) we need to provide the fully scoped name for this default value. // no idea why. It works without the scope in 4.1 template < class T, class A2, class A1, unsigned type = SENF_MPL_RV( senf::log::detail::RouteParameterCheck_(static_cast(0)) ) > struct RouteParameters {}; template struct RouteParameters : public RouteParameters {}; struct NilLevel { static unsigned const value = NONE::value; }; template <> struct RouteParameters { typedef mpl::nil Stream; typedef mpl::nil Area; typedef NilLevel Level; }; template struct RouteParameters : public RouteParameters { typedef RouteParameters base; BOOST_STATIC_ASSERT(( boost::is_same::value )); typedef T Stream; }; template struct RouteParameters : public RouteParameters { typedef RouteParameters base; BOOST_STATIC_ASSERT(( boost::is_same::value )); typedef T Area; }; template struct RouteParameters : public RouteParameters { typedef RouteParameters base; BOOST_STATIC_ASSERT(( boost::is_same::value )); typedef typename T::SENFLogArea Area; }; template struct RouteParameters : public RouteParameters { typedef RouteParameters base; BOOST_STATIC_ASSERT(( boost::is_same::value )); typedef T Level; }; template struct InstanceP { static RV * value() { return & T::instance(); } }; template struct InstanceP { static RV * value() { return 0; } }; #endif }}} //-///////////////////////////////////////////////////////////////////////////////////////////////// #endif // Local Variables: // mode: c++ // fill-column: 100 // comment-column: 40 // c-file-style: "senf" // indent-tabs-mode: nil // ispell-local-dictionary: "american" // compile-command: "scons -u test" // End: