]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: trace: add the file name and line number in the prefix
authorWilly Tarreau <w@1wt.eu>
Mon, 12 Aug 2019 15:27:09 +0000 (17:27 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 22 Aug 2019 18:21:00 +0000 (20:21 +0200)
We now pass an extra argument "where" to the trace() call, which
is supposed to be an ist made of the concatenation of the filename
and the line number. We only keep the last 10 chars from this string
since the end of file names is most often easy to recognize. This
gives developers useful information at very low cost.

include/proto/trace.h
src/trace.c

index 6767952cd2e0fd945d352cbd2c7a12e445a54468..7673892e893d609c4a396b68c85a6d7036873a9e 100644 (file)
@@ -34,7 +34,7 @@
 extern struct list trace_sources;
 extern THREAD_LOCAL struct buffer trace_buf;
 
-void __trace(uint64_t mask, struct trace_source *src, const struct ist msg);
+void __trace(uint64_t mask, struct trace_source *src, const struct ist where, const struct ist msg);
 
 /* return a single char to describe a trace state */
 static inline char trace_state_char(enum trace_state st)
@@ -66,10 +66,10 @@ static inline void trace_register_source(struct trace_source *source)
 }
 
 /* sends a trace for the given source */
-static inline void trace(uint64_t mask, struct trace_source *src, const struct ist msg)
+static inline void trace(uint64_t mask, struct trace_source *src, const struct ist where, const struct ist msg)
 {
        if (unlikely(src->state != TRACE_STATE_STOPPED))
-               __trace(mask, src, msg);
+               __trace(mask, src, where, msg);
 }
 
 #endif /* _PROTO_TRACE_H */
index 4f6a913cf3dfd13d1e99b2972a46740212e2da83..f68ff105823c1be705dc56bed5cd8c6c3a7b61ec 100644 (file)
@@ -49,8 +49,10 @@ REGISTER_PER_THREAD_ALLOC(alloc_trace_buffers_per_thread);
 REGISTER_PER_THREAD_FREE(free_trace_buffers_per_thread);
 
 /* write a message for the given trace source */
-void __trace(uint64_t mask, struct trace_source *src, const struct ist msg)
+void __trace(uint64_t mask, struct trace_source *src, const struct ist where, const struct ist msg)
 {
+       struct ist line[8];
+
        if (likely(src->state == TRACE_STATE_STOPPED))
                return;
 
@@ -75,8 +77,20 @@ void __trace(uint64_t mask, struct trace_source *src, const struct ist msg)
        if ((src->report_events & mask) == 0)
                goto end;
 
+       /* log the logging location truncated to 10 chars from the right so that
+        * the line number and the end of the file name are there.
+        */
+       line[0] = ist("[");
+       line[1] = where;
+       if (line[1].len > 10) {
+               line[1].ptr += (line[1].len - 10);
+               line[1].len = 10;
+       }
+       line[2] = ist("] ");
+       line[3] = msg;
+
        if (src->sink)
-               sink_write(src->sink, &msg, 1);
+               sink_write(src->sink, line, 4);
 
  end:
        /* check if we need to stop the trace now */