This is an automated email from the ASF dual-hosted git repository.
rjung pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat-connectors.git
The following commit(s) were added to refs/heads/main by this push:
new 557351ce3 Switch from logger to log context - part 2:
557351ce3 is described below
commit 557351ce323a6b009861e48cd583b123dfdd8c51
Author: Rainer Jung <[email protected]>
AuthorDate: Thu Jun 23 20:36:18 2022 +0200
Switch from logger to log context - part 2:
- Switch jk_log() implementation to use
jk_log_context_t instead of jk_loggaer_t,
especially make use of the context id if
provided.
---
native/common/jk_util.c | 33 +++++++++++++++++++++++++++++++--
1 file changed, 31 insertions(+), 2 deletions(-)
diff --git a/native/common/jk_util.c b/native/common/jk_util.c
index 6ecf11fbb..428d8a967 100644
--- a/native/common/jk_util.c
+++ b/native/common/jk_util.c
@@ -692,11 +692,12 @@ int jk_close_file_logger(jk_logger_t **l)
return JK_FALSE;
}
-int jk_log(jk_logger_t *l,
+int jk_log(jk_log_context_t *log_ctx,
const char *file, int line, const char *funcname, int level,
const char *fmt, ...)
{
int rc = 0;
+ jk_logger_t *l;
/*
* Need to reserve space for terminating zero byte
@@ -704,7 +705,7 @@ int jk_log(jk_logger_t *l,
* to the output routing.
*/
static int usable_size = LOG_BUFFER_SIZE - 3;
- if (!l || !file || !fmt) {
+ if (!log_ctx || !(l = log_ctx->logger) || !file || !fmt) {
return -1;
}
@@ -724,6 +725,34 @@ int jk_log(jk_logger_t *l,
used = set_time_str(buf, usable_size, l);
if (line) { /* line==0 only used for request log item */
+ /* Log [requestid] for all levels except REQUEST.
+ */
+ const char *context_id;
+ if (log_ctx == NULL) {
+ context_id = "-";
+ rc = 1;
+ } else if (log_ctx->id == NULL) {
+ context_id = "NO-ID";
+ rc = 5;
+ }
+ else {
+ context_id = log_ctx->id;
+ rc = (int)strlen(context_id);
+ }
+ if (usable_size - used >= rc + 3) {
+ strncpy(buf + used, "[", 1);
+ used += 1;
+ strncpy(buf + used, context_id, rc);
+ used += rc;
+ strncpy(buf + used, "] ", 2);
+ used += 2;
+ }
+ else {
+ strcpy(buf, "Logging failed in context_id formatting");
+ l->log(l, level, (int)strlen(buf), buf);
+ return 0;
+ }
+
/* Log [pid:threadid] for all levels except REQUEST.
* This information helps to correlate lines from different logs.
* Performance is no issue, because with production log levels
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]