Implement max syslog message length, as per RFC (1024 bytes total)

This commit is contained in:
Marko Zivanovic
2015-09-04 12:24:31 +02:00
parent 2dad24a22e
commit 464db0d1d2
3 changed files with 17 additions and 5 deletions
+7 -4
View File
@@ -28,11 +28,10 @@ SOFTWARE.
using namespace boost::posix_time;
using namespace std;
static time_facet* f = new time_facet("%b %e %H:%M:%S");
static stringstream ss;
static const time_facet* f = new time_facet("%b %e %H:%M:%S");
std::string RFC3164FormattedSyslogMessage::operator()() {
ss.str("");
stringstream ss;
ss.imbue(locale(locale::classic(), f));
ss << "<" << to_string(_message.priority()) << ">";
@@ -40,5 +39,9 @@ std::string RFC3164FormattedSyslogMessage::operator()() {
ss << _message.source() << " ";
ss << _message.message();
return ss.str();
string ret = ss.str();
if (ret.size() > MAX_LEN) {
ret = ret.substr(0, MAX_LEN);
}
return ret;
}
+1
View File
@@ -42,6 +42,7 @@ public:
std::string operator()();
private:
static const size_t MAX_LEN = 1024;
const SyslogMessage& _message;
};