4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at
9 // http://senf.berlios.de/license.html
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on,
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
15 // Software distributed under the License is distributed on an "AS IS" basis,
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
17 // for the specific language governing rights and limitations under the License.
19 // The Original Code is Fraunhofer FOKUS code.
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V.
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
26 // Stefan Bund <g0dil@berlios.de>
29 \brief SyslogTarget non-inline non-template implementation */
31 #include "SyslogTarget.hh"
32 //#include "SyslogTarget.ih"
35 #include <senf/Utils/Console/ParsedCommand.hh>
36 #include <senf/Utils/Console/Traits.hh>
37 #include <senf/Utils/Console/ScopedDirectory.hh>
39 //#include "SyslogTarget.mpp"
41 //-/////////////////////////////////////////////////////////////////////////////////////////////////
43 int const senf::log::SyslogTarget::LEVELMAP[8] = {
44 0, LOG_DEBUG, LOG_INFO, LOG_NOTICE, LOG_WARNING, LOG_CRIT, LOG_EMERG, 0 };
46 prefix_ void senf::log::SyslogTarget::v_write(time_type timestamp, std::string const & stream,
47 std::string const & area, unsigned level,
48 std::string const & message)
50 if (area != "senf::log::DefaultArea")
51 syslog(facility_ | LEVELMAP[level], "[%s] %s", area.c_str(), message.c_str());
53 syslog(facility_ | LEVELMAP[level], "%s", message.c_str());
59 SENF_CONSOLE_REGISTER_ENUM_MEMBER(SyslogTarget, LogFacility,
60 (AUTHPRIV)(CRON)(DAEMON)(FTP)(KERN)(LPR)(MAIL)(NEWS)(SYSLOG)
61 (USER)(UUCP)(LOCAL0)(LOCAL1)(LOCAL2)(LOCAL3)(LOCAL4)(LOCAL5)
66 prefix_ senf::log::SyslogTarget::RegisterConsole::RegisterConsole()
68 namespace kw = console::kw;
69 namespace fty = console::factory;
71 detail::TargetRegistry::instance().consoleDir()
72 .add("syslog-target",fty::Command(&RegisterConsole::create)
73 .arg("facility", "syslog facility to send messages to. One of\n"
74 " AUTHPRIV CRON DAEMON FTP KERN LPR MAIL NEWS SYSLOG USER\n"
75 " UUCP LOCAL0 LOCAL1 LOCAL2 LOCAL3 LOCAL4 LOCAL5 LOCAL6 LOCAL7",
76 kw::default_value = USER)
77 .doc("Create new syslog target. Examples:\n"
79 "Create new syslog target\n"
81 " <Directory '/sys/log/syslog'>\n"
83 "In a configuration file, create new syslog target and set some parameters (If\n"
84 "written on one line, this works at the console too:\n"
85 " /sys/log/syslog-target LOCAL2 {\n"
86 " route (IMPORTANT); # route all important messages\n"
87 " timeFormat \"\"; # use non-formatted time format\n"
88 " showArea false; # don't show log area\n"
92 prefix_ boost::shared_ptr<senf::console::DirectoryNode>
93 senf::log::SyslogTarget::RegisterConsole::create(LogFacility facility)
95 std::auto_ptr<Target> tp (new SyslogTarget(facility));
96 Target & target (*tp.get());
97 detail::TargetRegistry::instance().dynamicTarget(tp);
98 return target.consoleDir().node().thisptr();
101 //-/////////////////////////////////////////////////////////////////////////////////////////////////
103 //#include "SyslogTarget.mpp"
109 // comment-column: 40
110 // c-file-style: "senf"
111 // indent-tabs-mode: nil
112 // ispell-local-dictionary: "american"
113 // compile-command: "scons -u test"