Now adds the header to every line of the message received.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16079 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -116,14 +116,8 @@ write_to_log(const char *buffer, int32 length)
|
|||||||
static void
|
static void
|
||||||
syslog_output(syslog_message &message)
|
syslog_output(syslog_message &message)
|
||||||
{
|
{
|
||||||
// did we get this message already?
|
char header[128];
|
||||||
if (message.from == sLastThread
|
int32 headerLength;
|
||||||
&& !strncmp(message.message, sLastMessage, sizeof(sLastMessage))) {
|
|
||||||
sRepeatCount++;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
char buffer[SYSLOG_MESSAGE_BUFFER_SIZE + 64];
|
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
// parse & nicely print the time stamp from the message
|
// parse & nicely print the time stamp from the message
|
||||||
@@ -138,30 +132,51 @@ syslog_output(syslog_message &message)
|
|||||||
int facility = SYSLOG_FACILITY_INDEX(message.priority);
|
int facility = SYSLOG_FACILITY_INDEX(message.priority);
|
||||||
if (facility >= kNumFacilities)
|
if (facility >= kNumFacilities)
|
||||||
facility = SYSLOG_FACILITY_INDEX(LOG_USER);
|
facility = SYSLOG_FACILITY_INDEX(LOG_USER);
|
||||||
pos += snprintf(buffer + pos, sizeof(buffer) - pos, "%s", kFacilities[facility]);
|
pos += snprintf(header + pos, sizeof(header) - pos, "%s", kFacilities[facility]);
|
||||||
|
|
||||||
// add ident/thread ID
|
// add ident/thread ID
|
||||||
if (message.ident[0] == '\0') {
|
if (message.ident[0] == '\0') {
|
||||||
// ToDo: find out team name?
|
// ToDo: find out team name?
|
||||||
} else
|
} else
|
||||||
pos += snprintf(buffer + pos, sizeof(buffer) - pos, " '%s'", message.ident);
|
pos += snprintf(header + pos, sizeof(header) - pos, " '%s'", message.ident);
|
||||||
|
|
||||||
if (message.options & LOG_PID)
|
if (message.options & LOG_PID)
|
||||||
pos += snprintf(buffer + pos, sizeof(buffer) - pos, "[%ld]", message.from);
|
pos += snprintf(header + pos, sizeof(header) - pos, "[%ld]", message.from);
|
||||||
|
|
||||||
// add message itself
|
headerLength = pos + strlcpy(header + pos, ": ", sizeof(header) - pos);
|
||||||
int32 length = pos + snprintf(buffer + pos, sizeof(buffer) - pos, ": %s\n",
|
if (headerLength >= (int32)sizeof(header))
|
||||||
message.message);
|
headerLength = sizeof(header) - 1;
|
||||||
|
|
||||||
// TODO: insert header too every single line of the message
|
// add header to every line of the message and write it to the syslog
|
||||||
|
|
||||||
// ToDo: be less lazy about it - there is virtually no reason to truncate the message
|
char buffer[SYSLOG_MESSAGE_BUFFER_SIZE];
|
||||||
if (strlen(message.message) > sizeof(buffer) - pos - 1) {
|
pos = 0;
|
||||||
strcpy(&buffer[sizeof(buffer) - 9], "<TRUNC>\n");
|
|
||||||
length = sizeof(buffer) - 1;
|
while (true) {
|
||||||
|
strcpy(buffer, header);
|
||||||
|
int32 length;
|
||||||
|
|
||||||
|
const char *newLine = strchr(message.message + pos, '\n');
|
||||||
|
if (newLine != NULL) {
|
||||||
|
length = newLine - message.message + 1 - pos;
|
||||||
|
strlcpy(buffer + headerLength, message.message + pos, length + 1);
|
||||||
|
pos += length;
|
||||||
|
} else {
|
||||||
|
length = strlcpy(buffer + headerLength, message.message + pos,
|
||||||
|
sizeof(buffer) - headerLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
// dump message
|
length += headerLength;
|
||||||
|
|
||||||
|
if (length >= (int32)sizeof(buffer))
|
||||||
|
length = sizeof(buffer) - 1;
|
||||||
|
|
||||||
|
if (message.from == sLastThread
|
||||||
|
&& !strncmp(buffer + headerLength, sLastMessage, sizeof(sLastMessage))) {
|
||||||
|
// we got this message already
|
||||||
|
sRepeatCount++;
|
||||||
|
} else {
|
||||||
|
// dump message line
|
||||||
|
|
||||||
if (prepare_output() < B_OK
|
if (prepare_output() < B_OK
|
||||||
|| write_to_log(buffer, length) < B_OK) {
|
|| write_to_log(buffer, length) < B_OK) {
|
||||||
@@ -170,10 +185,17 @@ syslog_output(syslog_message &message)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// save this message to suppress repeated messages
|
// save this message to suppress repeated messages
|
||||||
strlcpy(sLastMessage, message.message, sizeof(sLastMessage));
|
strlcpy(sLastMessage, buffer + headerLength, sizeof(sLastMessage));
|
||||||
sLastThread = message.from;
|
sLastThread = message.from;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (newLine == NULL || !newLine[1]) {
|
||||||
|
// wrote last line of output
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
init_syslog_output(SyslogDaemon *daemon)
|
init_syslog_output(SyslogDaemon *daemon)
|
||||||
|
|||||||
Reference in New Issue
Block a user