// Custom includes
#include <sstream>
-#include "../../Socket/Protocols/INet/ConnectedUDPSocketHandle.hh"
#include <boost/algorithm/string/trim.hpp>
#include <boost/tokenizer.hpp>
#define prefix_
///////////////////////////////cc.p////////////////////////////////////////
-prefix_ senf::log::SyslogUDPTarget::SyslogUDPTarget(senf::INet4Address const & target,
- int facility)
- : facility_ (facility),
- handle_ ( senf::ConnectedUDPv4ClientSocketHandle(senf::INet4SocketAddress(target, 514u)) )
-{}
-
-prefix_ senf::log::SyslogUDPTarget::SyslogUDPTarget(senf::INet4SocketAddress const & target,
- int facility)
- : facility_ (facility),
- handle_ ( senf::ConnectedUDPv4ClientSocketHandle(target) )
-{}
-
-prefix_ senf::log::SyslogUDPTarget::SyslogUDPTarget(senf::INet6Address const & target,
- int facility)
- : facility_ (facility),
- handle_ ( senf::ConnectedUDPv6ClientSocketHandle(senf::INet6SocketAddress(target, 514u)) )
-{}
-
-prefix_ senf::log::SyslogUDPTarget::SyslogUDPTarget(senf::INet6SocketAddress const & target,
- int facility)
- : facility_ (facility),
- handle_ ( senf::ConnectedUDPv6ClientSocketHandle(target) )
-{}
-
prefix_ void senf::log::SyslogUDPTarget::v_write(time_type timestamp, std::string const & stream,
std::string const & area, unsigned level,
std::string const & message)
{
- std::stringstream prefix;
- prefix << '<' << (facility_ | senf::log::SyslogTarget::LEVELMAP[level]) << "> ";
- if (area != "senf::log::DefaultArea")
- prefix << '[' << area << "] ";
- std::string m (boost::trim_right_copy(message));
+ std::string m (message);
+ boost::trim_right(m);
+ detail::quoteNonPrintable(m);
+
+ std::stringstream prfstream;
+ // The space after the '>' is there on purpose: It ensures, that the prefix (which may be empty)
+ // or message will not inadvertently be interpreted as date or hostname by a receiving syslog
+ // daemon or proxy
+ prfstream << '<' << (facility_ | senf::log::SyslogTarget::LEVELMAP[level]) << "> "
+ << prefix(timestamp, stream, area, level);
+ std::string const & prf (prfstream.str());
typedef boost::char_separator<char> Separator;
typedef boost::tokenizer<Separator> Tokenizer;
Tokenizer::iterator i (tokenizer.begin());
Tokenizer::iterator const i_end (tokenizer.end());
- std::stringstream line;
+ std::string line;
+ unsigned sz (896-prf.size());
for (; i != i_end; ++i)
- for (unsigned j (0); j < i->size(); j += 896) {
- line << prefix.str() << std::string(*i, j, 896);
- handle_.write(line.str());
- line.str("");
+ for (unsigned j (0); j < i->size(); j += sz) {
+ line = prf;
+ line += std::string(*i, j, sz);
+ handle_.write(line);
}
}