Use the return value of `stream_generate_unique_id()` instead of relying on the
`unique_id` field of `struct stream` when handling the `%ID` log placeholder.
This also allowed to unify the "stream available" and "stream not available"
paths.

Reviewed-by: Volker Dusch <[email protected]>
---
 src/log.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/src/log.c b/src/log.c
index 270b7d511..21b53be36 100644
--- a/src/log.c
+++ b/src/log.c
@@ -5169,20 +5169,18 @@ size_t sess_build_logline_orig(struct session *sess, 
struct stream *s,
                                break;
 
                        case LOG_FMT_UNIQUEID: // %ID
-                               ret = NULL;
-                               if (s) {
-                                       /* if unique-id was not generated */
-                                       if (!isttest(s->unique_id) && 
!lf_expr_isempty(&sess->fe->format_unique_id)) {
-                                               stream_generate_unique_id(s, 
&sess->fe->format_unique_id);
-                                       }
-                                       ret = lf_text_len(tmplog, 
s->unique_id.ptr, s->unique_id.len, maxsize - (tmplog - dst), ctx);
-                               }
-                               else
-                                       ret = lf_text_len(tmplog, NULL, 0, 
maxsize - (tmplog - dst), ctx);
+                       {
+                               struct ist unique_id = IST_NULL;
+
+                               if (s && 
!lf_expr_isempty(&sess->fe->format_unique_id))
+                                       unique_id = 
stream_generate_unique_id(s, &sess->fe->format_unique_id);
+
+                               ret = lf_text_len(tmplog, istptr(unique_id), 
istlen(unique_id), maxsize - (tmplog - dst), ctx);
                                if (ret == NULL)
                                        goto out;
                                tmplog = ret;
                                break;
+                       }
 
                        case LOG_FMT_ORIGIN: // %OG
                                ret = lf_text(tmplog, 
log_orig_to_str(log_orig.id),
-- 
2.53.0



Reply via email to