mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-11-28 22:31:06 +01:00
MEDIUM: log: pass date strings to lf_rawtext()
Don't directly call functions that take date as argument and output the string representation to the log output buffer under sess_build_logline(), and instead build the strings in temporary buffers of fixed size (hopefully such functions, such as date2str_log() and gmt2str_log() procuce strings of known size), and then print the result using lf_rawtext() helper function. This way, we will be able to encode them automatically as regular string/text when new encoding methods are added. Because of this patch, we add a little overhead because we first generate the text into a temporary variable and then use lf_rawtext() to print it. Thus we have a double-copy, and this could have some performance implications that were not yet evaluated. Due to the small number of bytes that can end up being copied twice (< 30), we could be lucky and have no visible performance impact, but if we happen to see a significant impact, it could be useful to add a passthrough mechanism (to keep historical behavior) when no encoding is involved.
This commit is contained in:
parent
fcb7e4beaa
commit
0d1e99c086
48
src/log.c
48
src/log.c
@ -3243,56 +3243,92 @@ int sess_build_logline(struct session *sess, struct stream *s, char *dst, size_t
|
||||
break;
|
||||
|
||||
case LOG_FMT_DATE: // %t = accept date
|
||||
{
|
||||
char date_str[25]; // "26/Apr/2024:09:39:58.774"
|
||||
|
||||
get_localtime(logs->accept_date.tv_sec, &tm);
|
||||
ret = date2str_log(tmplog, &tm, &logs->accept_date, dst + maxsize - tmplog);
|
||||
if (!date2str_log(date_str, &tm, &logs->accept_date, sizeof(date_str)))
|
||||
goto out;
|
||||
ret = lf_rawtext(tmplog, date_str, dst + maxsize - tmplog, tmp);
|
||||
if (ret == NULL)
|
||||
goto out;
|
||||
tmplog = ret;
|
||||
break;
|
||||
}
|
||||
|
||||
case LOG_FMT_tr: // %tr = start of request date
|
||||
{
|
||||
char date_str[25]; // "26/Apr/2024:09:39:58.774"
|
||||
|
||||
/* Note that the timers are valid if we get here */
|
||||
tv_ms_add(&tv, &logs->accept_date, logs->t_idle >= 0 ? logs->t_idle + logs->t_handshake : 0);
|
||||
get_localtime(tv.tv_sec, &tm);
|
||||
ret = date2str_log(tmplog, &tm, &tv, dst + maxsize - tmplog);
|
||||
if (!date2str_log(date_str, &tm, &tv, sizeof(date_str)))
|
||||
goto out;
|
||||
ret = lf_rawtext(tmplog, date_str, dst + maxsize - tmplog, tmp);
|
||||
if (ret == NULL)
|
||||
goto out;
|
||||
tmplog = ret;
|
||||
break;
|
||||
}
|
||||
|
||||
case LOG_FMT_DATEGMT: // %T = accept date, GMT
|
||||
{
|
||||
char gmt_str[27]; // "26/Apr/2024:07:41:11 +0000"
|
||||
|
||||
get_gmtime(logs->accept_date.tv_sec, &tm);
|
||||
ret = gmt2str_log(tmplog, &tm, dst + maxsize - tmplog);
|
||||
if (!gmt2str_log(gmt_str, &tm, sizeof(gmt_str)))
|
||||
goto out;
|
||||
ret = lf_rawtext(tmplog, gmt_str, dst + maxsize - tmplog, tmp);
|
||||
if (ret == NULL)
|
||||
goto out;
|
||||
tmplog = ret;
|
||||
break;
|
||||
}
|
||||
|
||||
case LOG_FMT_trg: // %trg = start of request date, GMT
|
||||
{
|
||||
char gmt_str[27]; // "26/Apr/2024:07:41:11 +0000"
|
||||
|
||||
tv_ms_add(&tv, &logs->accept_date, logs->t_idle >= 0 ? logs->t_idle + logs->t_handshake : 0);
|
||||
get_gmtime(tv.tv_sec, &tm);
|
||||
ret = gmt2str_log(tmplog, &tm, dst + maxsize - tmplog);
|
||||
if (!gmt2str_log(gmt_str, &tm, sizeof(gmt_str)))
|
||||
goto out;
|
||||
ret = lf_rawtext(tmplog, gmt_str, dst + maxsize - tmplog, tmp);
|
||||
if (ret == NULL)
|
||||
goto out;
|
||||
tmplog = ret;
|
||||
break;
|
||||
}
|
||||
|
||||
case LOG_FMT_DATELOCAL: // %Tl = accept date, local
|
||||
{
|
||||
char localdate_str[27]; // "26/Apr/2024:09:42:32 +0200"
|
||||
|
||||
get_localtime(logs->accept_date.tv_sec, &tm);
|
||||
ret = localdate2str_log(tmplog, logs->accept_date.tv_sec, &tm, dst + maxsize - tmplog);
|
||||
if (!localdate2str_log(localdate_str, logs->accept_date.tv_sec, &tm, sizeof(localdate_str)))
|
||||
goto out;
|
||||
ret = lf_rawtext(tmplog, localdate_str, dst + maxsize - tmplog, tmp);
|
||||
if (ret == NULL)
|
||||
goto out;
|
||||
tmplog = ret;
|
||||
break;
|
||||
}
|
||||
|
||||
case LOG_FMT_trl: // %trl = start of request date, local
|
||||
{
|
||||
char localdate_str[27]; // "26/Apr/2024:09:42:32 +0200"
|
||||
|
||||
tv_ms_add(&tv, &logs->accept_date, logs->t_idle >= 0 ? logs->t_idle + logs->t_handshake : 0);
|
||||
get_localtime(tv.tv_sec, &tm);
|
||||
ret = localdate2str_log(tmplog, tv.tv_sec, &tm, dst + maxsize - tmplog);
|
||||
if (!localdate2str_log(localdate_str, tv.tv_sec, &tm, sizeof(localdate_str)))
|
||||
goto out;
|
||||
ret = lf_rawtext(tmplog, localdate_str, dst + maxsize - tmplog, tmp);
|
||||
if (ret == NULL)
|
||||
goto out;
|
||||
tmplog = ret;
|
||||
break;
|
||||
}
|
||||
|
||||
case LOG_FMT_TS: // %Ts
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user