X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=senf%2FUtils%2FLogger%2FTarget.cc;h=fa9993505681dffa367be44575b5a5357023db75;hb=394ced7000128fef7e753caea1deda8d55dec8e2;hp=1069656f4624aad18a514b68d2b29a3f0dd69362;hpb=21be434729b552e31b856b2f42fc978062d0dd55;p=senf.git diff --git a/senf/Utils/Logger/Target.cc b/senf/Utils/Logger/Target.cc index 1069656..fa99935 100644 --- a/senf/Utils/Logger/Target.cc +++ b/senf/Utils/Logger/Target.cc @@ -31,14 +31,12 @@ #include #include "ConsoleTarget.hh" #include -#include -#include //#include "Target.mpp" #define prefix_ -///////////////////////////////cc.p//////////////////////////////////////// +//-///////////////////////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////// +//-///////////////////////////////////////////////////////////////////////////////////////////////// // senf::log::Target namespace senf { @@ -48,19 +46,19 @@ namespace log { namespace detail { - SENF_CONSOLE_REGISTER_ENUM_MEMBER( TargetRegistry, Level, + SENF_CONSOLE_REGISTER_ENUM_MEMBER( TargetRegistry, Level, (VERBOSE)(NOTICE)(MESSAGE)(IMPORTANT)(CRITICAL)(FATAL) ); }}} prefix_ senf::log::Target::Target(std::string const & name) { - namespace kw = senf::console::kw; - namespace fty = senf::console::factory; + namespace kw = console::kw; + namespace fty = console::factory; detail::TargetRegistry::instance().registerTarget(this, name); consoleDir_() - .add("list", fty::Command(this, &Target::consoleList) + .add("list", fty::Command(&Target::consoleList, this) .doc("Show routing table\n" "\n" "Columns:\n" @@ -70,12 +68,14 @@ prefix_ senf::log::Target::Target(std::string const & name) " LEVEL match messages with level above this. Log levels in increasing order\n" " are:\n" " verbose, notice, message, important, critical, fatal\n" + " If the log level is listed as 'default', the streams default limit\n" + " applies.\n" " ACTION action to take: accept or reject") ); consoleDir_() - .add("route", fty::Command(this, &Target::consoleRoute) + .add("route", fty::Command(&Target::consoleRoute, this) .arg("index", "index at which to insert new rule") .arg("parameters", "log parameters. The log parameters select the log stream, log area\n" - " and log level. You may specify any combination of these parameterse\n" + " and log level. You may specify any combination of these parameters\n" " in any order. Use the '/sys/log/stream' and '/sys/log/areas' commands\n" " to list all valid streams and areas. Valid log levels are:\n" " VERBOSE NOTICE MESSAGE IMPORTANT CRITICAL FATAL") @@ -88,9 +88,10 @@ prefix_ senf::log::Target::Target(std::string const & name) "Examples:\n" "\n" " route ()\n" - " route all messages to this target.\n" + " route all messages with level above each streams default log limit to this\n" + " target.\n" "\n" - " route 1 (my::Class)\n" + " route 1 (my::Class VERBOSE)\n" " route all messages which are in the my::Class area. Insert this route after\n" " the first route,\n" "\n" @@ -108,13 +109,13 @@ prefix_ senf::log::Target::Target(std::string const & name) .arg("action", kw::default_value=ACCEPT) ); consoleDir_() .add("unroute", - fty::Command(this, static_cast(&Target::unroute)) + fty::Command(static_cast(&Target::unroute), this) .arg("index", "index of routing entry to remove") .overloadDoc("Remove routing entry with the given index") ); consoleDir_() - .add("unroute", fty::Command(this, &Target::consoleUnroute) + .add("unroute", fty::Command(&Target::consoleUnroute, this) .arg("parameters", "log parameters. The log parameters select the log stream, log area\n" - " and log level. You may specify any combination of these parameterse\n" + " and log level. You may specify any combination of these parameters\n" " in any order. Use the '/sys/log/stream' and '/sys/log/areas' commands\n" " to list all valid streams and areas. Valid log levels are:\n" " VERBOSE NOTICE MESSAGE IMPORTANT CRITICAL FATAL") @@ -122,7 +123,7 @@ prefix_ senf::log::Target::Target(std::string const & name) kw::default_value=ACCEPT) .overloadDoc("Remove the routing entry matching the specified arguments.") ); consoleDir_() - .add("flush", fty::Command(this, &Target::flush) + .add("flush", fty::Command(&Target::flush, this) .doc("Remove all routing entries clearing the routing table. This will disable all\n" "logging output on this target.") ); } @@ -214,7 +215,7 @@ prefix_ void senf::log::Target::flush() updateRoutingCache(i->stream_, i->area_); } -//////////////////////////////////////// +//-///////////////////////////////////////////////////////////////////////////////////////////////// // protected members prefix_ senf::console::ScopedDirectory<> & senf::log::Target::consoleDir() @@ -222,7 +223,7 @@ prefix_ senf::console::ScopedDirectory<> & senf::log::Target::consoleDir() return consoleDir_(); } -//////////////////////////////////////// +//-///////////////////////////////////////////////////////////////////////////////////////////////// // private members prefix_ void senf::log::Target::route(detail::StreamBase const * stream, @@ -285,7 +286,7 @@ prefix_ void senf::log::Target::updateRoutingCache(detail::StreamBase const * st unsigned limit (DISABLED::value); RIB::iterator i (rib_.begin()); RIB::iterator const i_end (rib_.end()); - for(; i != i_end; ++i) + for (; i != i_end; ++i) if ( (! i->stream_ || i->stream_ == stream) && (! i->area_ || i->area_ == area) && i->action_ == ACCEPT ) { @@ -325,22 +326,26 @@ namespace { return l.substr(l.size()-29); return l; } + + char const * levelNames[] = { + "NONE", "VERBOSE", "NOTICE", "MESSAGE", "IMPORTANT", "CRITICAL", "FATAL", "DISABLED" }; + + char const * levelNamesList[] = { + "default", "verbose", "notice", "message", "important", "critical", "fatal", "disabled" }; } prefix_ void senf::log::Target::consoleList(std::ostream & os) { - static char const * levels[] = { - "verbose", "verbose", "notice", "message", "important", "critical", "fatal", "disabled" }; boost::format fmt ("%2d %-29s %-29s %-9s %-6s\n"); os << fmt % "#" % "STREAM" % "AREA" % "LEVEL" % "ACTION"; unsigned n (0); for (iterator i (begin()); i != end(); ++i, ++n) - os << fmt - % n + os << fmt + % n % formatLabel(i->stream()) % formatLabel(i->area()) - % levels[i->level()] + % levelNamesList[i->level()] % (i->action() == ACCEPT ? "accept" : "reject"); } @@ -354,12 +359,12 @@ prefix_ void senf::log::Target::consoleUnroute(detail::LogParameters const & pm, unroute(pm.stream, pm.area, pm.level, action); } -/////////////////////////////////////////////////////////////////////////// +//-///////////////////////////////////////////////////////////////////////////////////////////////// // senf::log::detail::TargetRegistry prefix_ void senf::log::detail::TargetRegistry::dynamicTarget(std::auto_ptr target) { - namespace fty = senf::console::factory; + namespace fty = console::factory; target->consoleDir() .add("remove", fty::Command( @@ -397,20 +402,20 @@ prefix_ void senf::log::detail::TargetRegistry::consoleRemoveTarget(Target * tar prefix_ senf::log::detail::TargetRegistry::TargetRegistry() : fallbackRouting_(true) { - namespace kw = senf::console::kw; - namespace fty = senf::console::factory; + namespace kw = console::kw; + namespace fty = console::factory; console::sysdir().add("log", consoleDir_()); consoleDir_() - .add("areas", fty::Command(this, &TargetRegistry::consoleAreas) + .add("areas", fty::Command(&TargetRegistry::consoleAreas, this) .doc("List all areas") ); consoleDir_() - .add("streams", fty::Command(this, &TargetRegistry::consoleStreams) - .doc("List all streams") ); + .add("streams", fty::Command(&TargetRegistry::consoleStreams, this) + .doc("List all streams with the streams default runtime log level limit.") ); consoleDir_() - .add("message", fty::Command(this, &TargetRegistry::consoleWrite) + .add("message", fty::Command(&TargetRegistry::consoleWrite, this) .arg("parameters", "log parameters. The log parameters select the log stream, log area\n" - " and log level. You may specify any combination of these parameterse\n" + " and log level. You may specify any combination of these parameters\n" " in any order. Use the '/sys/log/stream' and '/sys/log/areas' commands\n" " to list all valid streams and areas. Valid log levels are:\n" " VERBOSE NOTICE MESSAGE IMPORTANT CRITICAL FATAL", @@ -424,7 +429,7 @@ prefix_ senf::log::detail::TargetRegistry::TargetRegistry() " message (FATAL) \"Program on fire\";\n" " message (VERBOSE senf::log::Debug) \"Debug message\";") ); consoleDir_() - .add("self", fty::Command(this, &TargetRegistry::consoleSelf) + .add("self", fty::Command(&TargetRegistry::consoleSelf, this) .doc("Get the log directory of the current network client. Example usage:\n" "\n" "Just get the log config directory\n" @@ -455,8 +460,10 @@ prefix_ void senf::log::detail::TargetRegistry::consoleStreams(std::ostream & os { StreamRegistry::iterator i (StreamRegistry::instance().begin()); StreamRegistry::iterator const i_end (StreamRegistry::instance().end()); - for (; i != i_end; ++i) - os << *i << "\n"; + for (; i != i_end; ++i) { + os << *i << " " + << levelNames[StreamRegistry::instance().lookup(*i)->defaultRuntimeLimit()] << "\n"; + } } prefix_ void senf::log::detail::TargetRegistry::consoleWrite(LogParameters pm, @@ -470,9 +477,9 @@ prefix_ boost::shared_ptr senf::log::detail::TargetRegistry::consoleSelf(std::ostream & os) { return senf::console::Client::get(os).consoleDir().node().thisptr(); -} +} -/////////////////////////////////////////////////////////////////////////// +//-///////////////////////////////////////////////////////////////////////////////////////////////// // senf::log::detail::LogParameters prefix_ void senf::log::detail::LogParameters::clear() @@ -492,8 +499,7 @@ prefix_ void senf::log::detail::LogParameters::setDefaults() level = MESSAGE::value; } -prefix_ senf::log::detail::LogParameters::LogParameters -senf::log::detail::LogParameters::defaultParameters() +prefix_ senf::log::detail::LogParameters senf::log::detail::LogParameters::defaultParameters() { LogParameters pm; pm.clear(); @@ -501,7 +507,7 @@ senf::log::detail::LogParameters::defaultParameters() return pm; } -/////////////////////////////////////////////////////////////////////////// +//-///////////////////////////////////////////////////////////////////////////////////////////////// // namespace members prefix_ std::ostream & senf::log::operator<<(std::ostream & os, senf::log::Target::action_t const & action) @@ -514,9 +520,6 @@ prefix_ std::ostream & senf::log::operator<<(std::ostream & os, senf::log::Targe namespace { - char const * levelNames[] = { - "NONE", "VERBOSE", "NOTICE", "MESSAGE", "IMPORTANT", "CRITICAL", "FATAL", "DISABLED" }; - void parseParamToken(std::string const & value, senf::log::detail::LogParameters & out) { senf::log::detail::StreamBase const * s ( @@ -536,7 +539,7 @@ namespace { out.area = a; return; } - + char const ** i ( std::find(levelNames+1, levelNames+sizeof(levelNames)/sizeof(levelNames[0])-1, value)); if (i == levelNames+sizeof(levelNames)/sizeof(levelNames[0])-1) @@ -569,13 +572,13 @@ senf_console_parse_argument(console::ParseCommandInfo::TokensRange const & token LogParameters & out) { out.clear(); - + for (console::ParseCommandInfo::TokensRange::iterator i (tokens.begin()); i != tokens.end(); ++i) parseParamToken(i->value(), out); } -////////////////////////////////////////////////////////////////////////// +//-///////////////////////////////////////////////////////////////////////////////////////////////// // I need to put this here, otherwise the file target will not be registered // if it is not used ... :-( @@ -583,7 +586,7 @@ senf::log::FileTarget::RegisterConsole senf::log::FileTarget::RegisterConsole::i senf::log::SyslogTarget::RegisterConsole senf::log::SyslogTarget::RegisterConsole::instance; senf::log::SyslogUDPTarget::RegisterConsole senf::log::SyslogUDPTarget::RegisterConsole::instance; -///////////////////////////////cc.e//////////////////////////////////////// +//-///////////////////////////////////////////////////////////////////////////////////////////////// #undef prefix_ //#include "Target.mpp"