00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00026 #include "SyslogTarget.hh"
00027
00028
00029
00030 #include <senf/Utils/Console/ParsedCommand.hh>
00031 #include <senf/Utils/Console/Traits.hh>
00032 #include <senf/Utils/Console/ScopedDirectory.hh>
00033
00034
00035 #define prefix_
00036
00037
00038 int const senf::log::SyslogTarget::LEVELMAP[8] = {
00039 0, LOG_DEBUG, LOG_INFO, LOG_NOTICE, LOG_WARNING, LOG_CRIT, LOG_EMERG, 0 };
00040
00041 prefix_ void senf::log::SyslogTarget::v_write(time_type timestamp, std::string const & stream,
00042 std::string const & area, unsigned level,
00043 std::string const & message)
00044 {
00045 if (area != "senf::log::DefaultArea")
00046 syslog(facility_ | LEVELMAP[level], "[%s] %s", area.c_str(), message.c_str());
00047 else
00048 syslog(facility_ | LEVELMAP[level], "%s", message.c_str());
00049 }
00050
00051 namespace senf {
00052 namespace log {
00053
00054 SENF_CONSOLE_REGISTER_ENUM_MEMBER(SyslogTarget, LogFacility,
00055 (AUTHPRIV)(CRON)(DAEMON)(FTP)(KERN)(LPR)(MAIL)(NEWS)(SYSLOG)
00056 (USER)(UUCP)(LOCAL0)(LOCAL1)(LOCAL2)(LOCAL3)(LOCAL4)(LOCAL5)
00057 (LOCAL6)(LOCAL7));
00058
00059 }}
00060
00061 prefix_ senf::log::SyslogTarget::RegisterConsole::RegisterConsole()
00062 {
00063 namespace kw = console::kw;
00064 namespace fty = console::factory;
00065
00066 detail::TargetRegistry::instance().consoleDir()
00067 .add("syslog-target",fty::Command(&RegisterConsole::create)
00068 .arg("facility", "syslog facility to send messages to. One of\n"
00069 " AUTHPRIV CRON DAEMON FTP KERN LPR MAIL NEWS SYSLOG USER\n"
00070 " UUCP LOCAL0 LOCAL1 LOCAL2 LOCAL3 LOCAL4 LOCAL5 LOCAL6 LOCAL7",
00071 kw::default_value = USER)
00072 .doc("Create new syslog target. Examples:\n"
00073 "\n"
00074 "Create new syslog target\n"
00075 " $ syslog-target\n"
00076 " <Directory '/sys/log/syslog'>\n"
00077 "\n"
00078 "In a configuration file, create new syslog target and set some parameters (If\n"
00079 "written on one line, this works at the console too:\n"
00080 " /sys/log/syslog-target LOCAL2 {\n"
00081 " route (IMPORTANT); # route all important messages\n"
00082 " timeFormat \"\"; # use non-formatted time format\n"
00083 " showArea false; # don't show log area\n"
00084 " }\n") );
00085 }
00086
00087 prefix_ boost::shared_ptr<senf::console::DirectoryNode>
00088 senf::log::SyslogTarget::RegisterConsole::create(LogFacility facility)
00089 {
00090 std::auto_ptr<Target> tp (new SyslogTarget(facility));
00091 Target & target (*tp.get());
00092 detail::TargetRegistry::instance().dynamicTarget(tp);
00093 return target.consoleDir().node().thisptr();
00094 }
00095
00096
00097 #undef prefix_
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109