22 #include <boost/algorithm/string/trim.hpp> 23 #include <boost/tokenizer.hpp> 33 prefix_ void senf::log::SyslogUDPTarget::init()
35 namespace kw = console::kw;
36 namespace fty = console::factory;
40 .
add(
"format", fty::Command(&SyslogUDPTarget::consoleFormat,
this)
41 .doc(
"Show the current log message format.") );
44 .arg(
"flag",
"new syslog format state",
45 kw::default_value=
true)
46 .doc(
"Change the syslog format flag. By default, syslog formating is enabled. In this\n" 47 "state, the udp target will send out minimal but valid syslog format messages.\n" 49 "Disabling syslog format will remove the syslog prefix. Log messages will then be\n" 50 "sent using plain UDP.") );
53 prefix_ void senf::log::SyslogUDPTarget::v_write(
time_type timestamp, std::string
const & stream,
54 std::string
const & area,
unsigned level,
55 std::string
const & message)
57 std::string m (message);
61 std::stringstream prfstream;
67 prfstream <<
prefix(timestamp, stream, area, level);
68 std::string
const & prf (prfstream.str());
70 typedef boost::char_separator<char> Separator;
71 typedef boost::tokenizer<Separator> Tokenizer;
72 Separator separator (
"\n");
73 Tokenizer tokenizer (m, separator);
74 Tokenizer::iterator i (tokenizer.begin());
75 Tokenizer::iterator
const i_end (tokenizer.end());
78 unsigned sz (896-prf.size());
79 for (; i != i_end; ++i)
80 for (
unsigned j (0); j < i->size(); j += sz) {
82 line += std::string(*i, j, sz);
92 prefix_ void senf::log::SyslogUDPTarget::consoleFormat(std::ostream & os)
94 LogFormat::consoleFormat(os);
95 os <<
"syslog prefix " << (syslogFormat_ ?
"enabled" :
"disabled") <<
"\n";
108 prefix_ senf::log::SyslogUDPTarget::RegisterConsole::RegisterConsole()
110 namespace kw = console::kw;
111 namespace fty = console::factory;
113 detail::TargetRegistry::instance().consoleDir()
117 >(&RegisterConsole::create)
118 .arg(
"address",
"target address to send log messages to")
119 .arg(
"facility",
"syslog facility to send messages to. One of\n" 120 " AUTHPRIV CRON DAEMON FTP KERN LPR MAIL NEWS SYSLOG USER\n" 121 " UUCP LOCAL0 LOCAL1 LOCAL2 LOCAL3 LOCAL4 LOCAL5 LOCAL6 LOCAL7",
122 kw::default_value =
USER)
123 .doc(
"Create new udp target. The {address} can be an IPv4 or IPv6 address. If the port\n" 124 "number is omitted, it defaults to the default syslog port 514. Examples:\n" 126 "Create new udp target sending messages to the syslog daemon running at localhost\n" 127 " $ udp-target localhost\n" 128 " <Directory '/sys/log/udp-127.0.0.1:514'>\n" 130 "In a configuration file, create new udp target and set some parameters (If\n" 131 "written on one line, this works at the console too:\n" 132 " /sys/log/udp-target localhost:2345 LOCAL2 {\n" 133 " route (IMPORTANT); # route all important messages\n" 134 " timeFormat \"\"; # use non-formatted time format\n" 135 " showArea false; # don't show log area\n" 136 " syslog false; # no syslog format, just plain udp\n" 138 detail::TargetRegistry::instance().consoleDir()
141 >(&RegisterConsole::create)
143 .arg(
"facility", kw::default_value =
USER) );
144 detail::TargetRegistry::instance().consoleDir()
147 >(&RegisterConsole::create)
149 .arg(
"facility", kw::default_value =
USER) );
150 detail::TargetRegistry::instance().consoleDir()
153 >(&RegisterConsole::create)
155 .arg(
"facility", kw::default_value =
USER) );
158 prefix_ boost::shared_ptr<senf::console::DirectoryNode>
159 senf::log::SyslogUDPTarget::RegisterConsole::create(INet4SocketAddress
const & target,
164 detail::TargetRegistry::instance().dynamicTarget(std::move(tp));
165 return tg.consoleDir().node().thisptr();
168 prefix_ boost::shared_ptr<senf::console::DirectoryNode>
169 senf::log::SyslogUDPTarget::RegisterConsole::create(INet4Address
const & target,
174 detail::TargetRegistry::instance().dynamicTarget(std::move(tp));
175 return tg.consoleDir().node().thisptr();
178 prefix_ boost::shared_ptr<senf::console::DirectoryNode>
179 senf::log::SyslogUDPTarget::RegisterConsole::create(INet6SocketAddress
const & target,
184 detail::TargetRegistry::instance().dynamicTarget(std::move(tp));
185 return tg.consoleDir().node().thisptr();
188 prefix_ boost::shared_ptr<senf::console::DirectoryNode>
189 senf::log::SyslogUDPTarget::RegisterConsole::create(INet6Address
const & target,
194 detail::TargetRegistry::instance().dynamicTarget(std::move(tp));
195 return tg.consoleDir().node().thisptr();
#define SENF_MEMBINDFNP(ret, cls, fn, args)
static int const LEVELMAP[8]
bool syslog() const
true, if using syslog format, false otherwise
boost::shared_ptr< DirectoryNode > ptr
void quoteNonPrintable(std::string &s)
SyslogTarget public header.
SENF_CONSOLE_REGISTER_ENUM_MEMBER(SyslogTarget, LogFacility,(AUTHPRIV)(CRON)(DAEMON)(FTP)(KERN)(LPR)(MAIL)(NEWS)(SYSLOG)(USER)(UUCP)(LOCAL0)(LOCAL1)(LOCAL2)(LOCAL3)(LOCAL4)(LOCAL5)(LOCAL6)(LOCAL7))
senf::console::ScopedDirectory & consoleDir()
Get console/config directory.
GenericNode::ptr remove(std::string const &name)
config::time_type time_type
boost::range_const_iterator< ForwardReadableRange const >::type write(ForwardReadableRange const &range)
SyslogUDPTarget(INet4Address const &target, int facility=LOG_USER)
SyslogUDPTarget public header.
Target(std::string const &name)
NodeType & add(std::string const &name, boost::shared_ptr< NodeType > node)