4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@berlios.de>
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 \brief SyslogUDPTarget non-inline non-template implementation */
26 #include "SyslogUDPTarget.hh"
27 //#include "SyslogUDPTarget.ih"
31 #include <boost/algorithm/string/trim.hpp>
32 #include <boost/tokenizer.hpp>
33 #include "../Console/Console.hh"
35 //#include "SyslogUDPTarget.mpp"
37 ///////////////////////////////cc.p////////////////////////////////////////
39 prefix_ void senf::log::SyslogUDPTarget::v_write(time_type timestamp, std::string const & stream,
40 std::string const & area, unsigned level,
41 std::string const & message)
43 std::string m (message);
45 detail::quoteNonPrintable(m);
47 std::stringstream prfstream;
48 // The space after the '>' is there on purpose: It ensures, that the prefix (which may be empty)
49 // or message will not inadvertently be interpreted as date or hostname by a receiving syslog
51 prfstream << '<' << (facility_ | senf::log::SyslogTarget::LEVELMAP[level]) << "> "
52 << prefix(timestamp, stream, area, level);
53 std::string const & prf (prfstream.str());
55 typedef boost::char_separator<char> Separator;
56 typedef boost::tokenizer<Separator> Tokenizer;
57 Separator separator ("\n");
58 Tokenizer tokenizer (m, separator);
59 Tokenizer::iterator i (tokenizer.begin());
60 Tokenizer::iterator const i_end (tokenizer.end());
63 unsigned sz (896-prf.size());
64 for (; i != i_end; ++i)
65 for (unsigned j (0); j < i->size(); j += sz) {
67 line += std::string(*i, j, sz);
75 SENF_CONSOLE_REGISTER_ENUM_MEMBER(SyslogUDPTarget, LogFacility,
76 (AUTHPRIV)(CRON)(DAEMON)(FTP)(KERN)(LPR)(MAIL)(NEWS)(SYSLOG)
77 (USER)(UUCP)(LOCAL0)(LOCAL1)(LOCAL2)(LOCAL3)(LOCAL4)(LOCAL5)
82 prefix_ senf::log::SyslogUDPTarget::RegisterConsole::RegisterConsole()
84 namespace kw = senf::console::kw;
86 detail::TargetRegistry::instance().consoleDir().add(
87 "udp-target", static_cast<void (*)(INet4SocketAddress const &, LogFacility)>(
88 &RegisterConsole::create))
89 .arg("address", "target address to send log messages to")
90 .arg("facility", "syslog facility to send messages to. One of\n"
91 " AUTHPRIV, CRON, DAEMON, FTP, KERN, LPR, MAIL, NEWS, SYSLOG, USER,\n"
92 " UUCP, LOCAL0, LOCAL1, LOCAL2, LOCAL3, LOCAL4, LOCAL5, LOCAL6, LOCAL7",
93 kw::default_value = USER)
94 .doc("Create new udp target. The {address} can be an IPv4 or IPv6 address. If the port\n"
95 "number is omitted, it defaults to the default syslog port 514.");
96 detail::TargetRegistry::instance().consoleDir().add(
97 "udp-target", static_cast<void (*)(INet4Address const &, LogFacility)>(
98 &RegisterConsole::create))
100 .arg("facility", kw::default_value = USER);
101 detail::TargetRegistry::instance().consoleDir().add(
102 "udp-target", static_cast<void (*)(INet6SocketAddress const &, LogFacility)>(
103 &RegisterConsole::create))
105 .arg("facility", kw::default_value = USER);
106 detail::TargetRegistry::instance().consoleDir().add(
107 "udp-target", static_cast<void (*)(INet6Address const &, LogFacility)>(
108 &RegisterConsole::create))
110 .arg("facility", kw::default_value = USER);
114 senf::log::SyslogUDPTarget::RegisterConsole::create(senf::INet4SocketAddress const & target,
115 LogFacility facility)
117 detail::TargetRegistry::instance().dynamicTarget(
118 std::auto_ptr<Target>(new SyslogUDPTarget(target, facility)));
122 senf::log::SyslogUDPTarget::RegisterConsole::create(senf::INet4Address const & target,
123 LogFacility facility)
125 detail::TargetRegistry::instance().dynamicTarget(
126 std::auto_ptr<Target>(new SyslogUDPTarget(target, facility)));
130 senf::log::SyslogUDPTarget::RegisterConsole::create(senf::INet6SocketAddress const & target,
131 LogFacility facility)
133 detail::TargetRegistry::instance().dynamicTarget(
134 std::auto_ptr<Target>(new SyslogUDPTarget(target, facility)));
138 senf::log::SyslogUDPTarget::RegisterConsole::create(senf::INet6Address const & target,
139 LogFacility facility)
141 detail::TargetRegistry::instance().dynamicTarget(
142 std::auto_ptr<Target>(new SyslogUDPTarget(target, facility)));
145 ///////////////////////////////cc.e////////////////////////////////////////
147 //#include "SyslogUDPTarget.mpp"
153 // comment-column: 40
154 // c-file-style: "senf"
155 // indent-tabs-mode: nil
156 // ispell-local-dictionary: "american"
157 // compile-command: "scons -u test"