Commit 753d5a7f authored by Pekka Pessi's avatar Pekka Pessi

tport_logging.c: Added separators around messages logged by tport_log_msg().

Maximum length of logged line is now 2048 (including final \n).

tport_internal.h, tport.c, tport_threadpool.c: updated
tport_log_msg()prototype.

test_tport.c: using test protocol version on request line.

darcs-hash:20060823104436-65a35-390e8c6bab982c85eb95c680f09c34cd960b8365.gz
parent f2e7f9f7
......@@ -261,6 +261,8 @@ static int test_msg_md5(tp_test_t *tt, msg_t *msg)
END();
}
#define VERSION MSG_TEST_VERSION_CURRENT
static int new_test_msg(tp_test_t *tt, msg_t **retval,
char const *ident,
int N, int len)
......@@ -290,7 +292,7 @@ static int new_test_msg(tp_test_t *tt, msg_t **retval,
TEST(msg_maxsize(msg, 1024 + N * len), 0);
TEST_1(rq = msg_request_make(home, "DO im:foo@faa MSG/1.0"));
TEST_1(rq = msg_request_make(home, "DO im:foo@faa " VERSION));
TEST(msg_header_insert(msg, (void *)tst, (msg_header_t *)rq), 0);
TEST_1(u = msg_unknown_make(home, "Foo: faa"));
......@@ -723,7 +725,7 @@ static int udp_test(tp_test_t *tt)
TEST_1(tst = msg_test_public(msg));
TEST_1(home = msg_home(msg));
TEST_1(rq = msg_request_make(home, "DO im:foo@faa MSG/1.0"));
TEST_1(rq = msg_request_make(home, "DO im:foo@faa " VERSION));
TEST(msg_header_insert(msg, (void *)tst, (msg_header_t *)rq), 0);
TEST_1(u = msg_unknown_make(home, "Foo: faa"));
......
......@@ -2749,7 +2749,7 @@ void tport_deliver(tport_t *self,
}
else if (self->tp_master->mr_log && msg != self->tp_rlogged) {
char const *via = "recv";
tport_log_msg(self, msg, via, "from", " ", now);
tport_log_msg(self, msg, via, "from", now);
self->tp_rlogged = msg;
}
......@@ -3159,7 +3159,7 @@ int tport_send_msg(tport_t *self, msg_t *msg,
self->tp_unsent = NULL, self->tp_unsentlen = 0;
if (n > 0 && self->tp_master->mr_log && self->tp_slogged != msg) {
tport_log_msg(self, msg, "send", "to", " ", now);
tport_log_msg(self, msg, "send", "to", now);
self->tp_slogged = msg;
}
......@@ -3587,7 +3587,7 @@ void tport_send_queue(tport_t *self)
return;
if (n > 0 && self->tp_master->mr_log && self->tp_slogged != msg) {
tport_log_msg(self, msg, "send", "to", " ", now);
tport_log_msg(self, msg, "send", "to", now);
self->tp_slogged = msg;
}
......
......@@ -420,7 +420,7 @@ void tport_error_report(tport_t *self, int errcode,
void tport_open_log(tport_master_t *mr, tagi_t *tags);
void tport_log_msg(tport_t *tp, msg_t *msg, char const *what,
char const *via, char const *indent, su_time_t now);
char const *via, su_time_t now);
void tport_dump_iovec(tport_t const *self, msg_t *msg,
int n, su_iovec_t const iov[], int iovused,
char const *what, char const *how);
......
......@@ -178,13 +178,17 @@ void tport_dump_iovec(tport_t const *self, msg_t *msg,
/** Log the message. */
void tport_log_msg(tport_t *self, msg_t *msg,
char const *what, char const *via,
char const *first, su_time_t now)
su_time_t now)
{
char stamp[128];
msg_iovec_t iov[80];
int i, n, iovlen = msg_iovec(msg, iov, 80);
int i, iovlen = msg_iovec(msg, iov, 80);
int skip_lf = 0, linelen = 0;
char const *prefix = first;
size_t n, logged = 0, truncated = 0;
#define MSG_SEPARATOR \
"------------------------------------------------------------------------\n"
#define MAX_LINELEN 2047
if (iovlen < 0) return;
......@@ -193,56 +197,55 @@ void tport_log_msg(tport_t *self, msg_t *msg,
tport_stamp(self, msg, stamp, what, n, via, now);
su_log(stamp);
for (i = 0; i < iovlen && i < 80; i++) {
su_log(" " MSG_SEPARATOR);
for (i = 0; truncated == 0 && i < iovlen && i < 80; i++) {
char *s = iov[i].mv_base, *end = s + iov[i].mv_len;
int n;
if (skip_lf && s < end && s[0] == '\n') { s++; skip_lf = 0; }
if (skip_lf && s < end && s[0] == '\n') { s++; logged++; skip_lf = 0; }
while (s < end) {
if (s[0] == '\0') {
int j, len = s - (char *)iov[i].mv_base;
for (j = 0; j < i; j++)
len += iov[j].mv_len;
su_log("\n%s*** message truncated at %d\n", prefix, len);
return;
truncated = logged;
break;
}
n = strncspn(s, end - s, "\r\n");
if (prefix) {
su_log("%s", prefix); linelen = n;
} else {
linelen += n;
}
su_log("%.*s", n, s);
if (s + n < end) {
su_log("\n");
prefix = first;
}
else {
prefix = "";
if (linelen + n > MAX_LINELEN) {
n = MAX_LINELEN - n - linelen;
truncated = logged + n;
}
s += n;
/* Skip a eol */
if (s < end) {
if (s + 1 < end && s[0] == '\r' && s[1] == '\n')
s += 2;
else if (s[0] == '\r')
s++, (skip_lf = s + 1 == end);
else if (s[0] == '\n')
s++;
su_log("%s%.*s", linelen > n ? "" : " ", n, s);
s += n, linelen += n, logged += n;
if (truncated)
break;
if (s == end)
continue;
linelen = 0;
su_log("\n");
/* Skip eol */
if (s[0] == '\r') {
s++, logged++;
if (s == end) {
skip_lf = 1;
continue;
}
}
if (s[0] == '\n')
s++, logged++;
}
}
if (linelen) su_log("\n");
su_log("%s " MSG_SEPARATOR, linelen > 0 ? "\n" : "");
if (i == 80) {
int j, len = 0;
for (j = 0; j < i; j++)
len += iov[j].mv_len;
su_log("\n%s*** message truncated at %d\n", prefix, len);
return;
}
if (!truncated && i == 80)
truncated = logged;
if (truncated)
su_log(" *** message truncated at %d ***\n", truncated);
}
......@@ -802,7 +802,7 @@ void thrp_udp_send_report(su_root_magic_t *magic,
thrp, tpd, 1000 * su_time_diff(su_now(), tpd->tpd_when)));
if (tp->tp_master->mr_log)
tport_log_msg(tp, tpd->tpd_msg, "sent", "to", " ", tpd->tpd_when);
tport_log_msg(tp, tpd->tpd_msg, "sent", "to", tpd->tpd_when);
if (tpd->tpd_errorcode)
tport_error_report(tp, tpd->tpd_errorcode, msg_addr(tpd->tpd_msg));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment