fixes for g++ 4.5 (some members returned "the constructor, not the type")
[senf.git] / senf / Utils / Logger / Target.cc
index 9c7968c..08b2ab4 100644 (file)
 #include <boost/format.hpp>
 #include "ConsoleTarget.hh"
 #include <senf/Utils/Console/Console.hh>
-#include <senf/Utils/Console/Sysdir.hh>
-#include <senf/Utils/membind.hh>
 
 //#include "Target.mpp"
 #define prefix_
-///////////////////////////////cc.p////////////////////////////////////////
+//-/////////////////////////////////////////////////////////////////////////////////////////////////
 
-///////////////////////////////////////////////////////////////////////////
+//-/////////////////////////////////////////////////////////////////////////////////////////////////
 // senf::log::Target
 
 namespace senf {
@@ -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(&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"
@@ -114,7 +115,7 @@ prefix_ senf::log::Target::Target(std::string const & name)
     consoleDir_()
         .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")
@@ -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,
@@ -325,12 +326,16 @@ 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";
@@ -340,7 +345,7 @@ prefix_ void senf::log::Target::consoleList(std::ostream & os)
             % n
             % formatLabel(i->stream())
             % formatLabel(i->area())
-            % levels[i->level()]
+            % levelNamesList[i->level()]
             % (i->action() == ACCEPT ? "accept" : "reject");
 }
 
@@ -354,7 +359,7 @@ 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> target)
@@ -406,11 +411,11 @@ prefix_ senf::log::detail::TargetRegistry::TargetRegistry()
              .doc("List all areas") );
     consoleDir_()
         .add("streams", fty::Command(&TargetRegistry::consoleStreams, this)
-             .doc("List all streams") );
+             .doc("List all streams with the streams default runtime log level limit.") );
     consoleDir_()
         .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",
@@ -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,
@@ -472,7 +479,7 @@ 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 (
@@ -575,7 +578,7 @@ senf_console_parse_argument(console::ParseCommandInfo::TokensRange const & token
         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"