diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2023-10-12 02:46:37 +0000 |
---|---|---|
committer | Laurent Bercot <ska@appnovation.com> | 2023-10-12 02:46:37 +0000 |
commit | d9492e8561fe5373b1428c6d7cff4f25e2796a55 (patch) | |
tree | 8e0b77e1b8f4964f9a154ce89209f25e093a0f8f | |
parent | 541325d00c7078d063ea97333d3c9c64d6b6c7b6 (diff) | |
download | tipidee-d9492e8561fe5373b1428c6d7cff4f25e2796a55.tar.xz |
Add host_as_prefix logging for request/resource/answer
Signed-off-by: Laurent Bercot <ska@appnovation.com>
-rw-r--r-- | src/include/tipidee/log.h | 5 | ||||
-rw-r--r-- | src/libtipidee/tipidee_log_answer.c | 19 | ||||
-rw-r--r-- | src/libtipidee/tipidee_log_request.c | 17 | ||||
-rw-r--r-- | src/libtipidee/tipidee_log_resource.c | 17 | ||||
-rw-r--r-- | src/libtipidee/tipidee_log_start.c | 4 |
5 files changed, 47 insertions, 15 deletions
diff --git a/src/include/tipidee/log.h b/src/include/tipidee/log.h index 0fe44ce..29d621f 100644 --- a/src/include/tipidee/log.h +++ b/src/include/tipidee/log.h @@ -19,6 +19,7 @@ #define TIPIDEE_LOG_START 0x100 #define TIPIDEE_LOG_CLIENTIP 0x0200 #define TIPIDEE_LOG_CLIENTHOST 0x0400 +#define TIPIDEE_LOG_HOSTASPREFIX 0x1000 #define TIPIDEE_LOG_DEFAULT (TIPIDEE_LOG_REQUEST | TIPIDEE_LOG_ANSWER | TIPIDEE_LOG_SIZE) @@ -35,7 +36,7 @@ extern void tipidee_log_start (uint32_t, char const *, char const *) ; extern void tipidee_log_exit (uint32_t, unsigned int) ; extern void tipidee_log_request (uint32_t, tipidee_rql const *, char const *, char const *, stralloc *) ; -extern void tipidee_log_resource (uint32_t, char const *, char const *, tipidee_resattr const *) ; -extern void tipidee_log_answer (uint32_t, unsigned int, off_t) ; +extern void tipidee_log_resource (uint32_t, tipidee_rql const *, char const *, char const *, tipidee_resattr const *) ; +extern void tipidee_log_answer (uint32_t, tipidee_rql const *, unsigned int, off_t) ; #endif diff --git a/src/libtipidee/tipidee_log_answer.c b/src/libtipidee/tipidee_log_answer.c index beedb61..b6e4617 100644 --- a/src/libtipidee/tipidee_log_answer.c +++ b/src/libtipidee/tipidee_log_answer.c @@ -8,17 +8,26 @@ #include <tipidee/log.h> -void tipidee_log_answer (uint32_t v, unsigned int status, off_t size) +void tipidee_log_answer (uint32_t v, tipidee_rql const *rql, unsigned int status, off_t size) { + char const *a[6] = { PROG, ": info:" } ; + size_t m = 2 ; char fmtstatus[UINT_FMT] ; + char fmtsize[UINT64_FMT] ; if (!(v & TIPIDEE_LOG_ANSWER)) return ; + if (v & TIPIDEE_LOG_HOSTASPREFIX) + { + a[m++] = " host " ; + a[m++] = rql->uri.host ; + } fmtstatus[uint_fmt(fmtstatus, status)] = 0 ; + a[m++] = " answer " ; + a[m++] = fmtstatus ; if (size) { - char fmtsize[UINT64_FMT] ; fmtsize[uint64_fmt(fmtsize, size)] = 0 ; - strerr_warni4x("answer ", fmtstatus, " size ", fmtsize) ; + a[m++] = " size " ; + a[m++] = fmtsize ; } - else - strerr_warni2x("answer ", fmtstatus) ; + strerr_warnv(a, m) ; } diff --git a/src/libtipidee/tipidee_log_request.c b/src/libtipidee/tipidee_log_request.c index 666297d..a789ca5 100644 --- a/src/libtipidee/tipidee_log_request.c +++ b/src/libtipidee/tipidee_log_request.c @@ -11,8 +11,8 @@ void tipidee_log_request (uint32_t v, tipidee_rql const *rql, char const *referrer, char const *ua, stralloc *sa) { - char const *a[14] = { "info: request " } ; - size_t m = 1 ; + char const *a[16] = { PROG, ": info:" } ; + size_t m = 2 ; size_t start = sa->len ; size_t refpos = start, uapos = start ; if (!(v & TIPIDEE_LOG_REQUEST)) return ; @@ -27,9 +27,18 @@ void tipidee_log_request (uint32_t v, tipidee_rql const *rql, char const *referr uapos = sa->len ; if (!string_quotes(sa, ua) || !stralloc_0(sa)) goto err ; } + if (v & TIPIDEE_LOG_HOSTASPREFIX) + { + a[m++] = " host " ; + a[m++] = rql->uri.host ; + } + a[m++] = " request " ; a[m++] = tipidee_method_tostr(rql->m) ; - a[m++] = " host " ; - a[m++] = rql->uri.host ; + if (!(v & TIPIDEE_LOG_HOSTASPREFIX)) + { + a[m++] = " host " ; + a[m++] = rql->uri.host ; + } a[m++] = " path " ; a[m++] = sa->s + start ; if (rql->uri.query) diff --git a/src/libtipidee/tipidee_log_resource.c b/src/libtipidee/tipidee_log_resource.c index dc525a5..6387027 100644 --- a/src/libtipidee/tipidee_log_resource.c +++ b/src/libtipidee/tipidee_log_resource.c @@ -4,8 +4,21 @@ #include <tipidee/log.h> -void tipidee_log_resource (uint32_t v, char const *docroot, char const *file, tipidee_resattr const *ra) +void tipidee_log_resource (uint32_t v, tipidee_rql const *rql, char const *docroot, char const *file, tipidee_resattr const *ra) { + char const *a[8] = { PROG, ": info:" } ; + size_t m = 2 ; if (!(v & TIPIDEE_LOG_RESOURCE)) return ; - strerr_warni6x("docroot ", docroot, " file ", file, " type ", ra->iscgi ? ra->isnph ? "nph" : "cgi" : ra->content_type) ; + if (v & TIPIDEE_LOG_HOSTASPREFIX) + { + a[m++] = " host " ; + a[m++] = rql->uri.host ; + } + a[m++] = " docroot " ; + a[m++] = docroot ; + a[m++] = " file " ; + a[m++] = file ; + a[m++] = " type " ; + a[m++] = ra->iscgi ? ra->isnph ? "nph" : "cgi" : ra->content_type ; + strerr_warnv(a, m) ; } diff --git a/src/libtipidee/tipidee_log_start.c b/src/libtipidee/tipidee_log_start.c index 34284af..b280301 100644 --- a/src/libtipidee/tipidee_log_start.c +++ b/src/libtipidee/tipidee_log_start.c @@ -8,8 +8,8 @@ void tipidee_log_start (uint32_t v, char const *ip, char const *host) { - char const *a[5] = { "info: start" } ; - size_t m = 1 ; + char const *a[6] = { PROG, ": info: start" } ; + size_t m = 2 ; if (!(v & TIPIDEE_LOG_START)) return ; if (v & TIPIDEE_LOG_CLIENTIP) { |