Skip to content

Commit 5a74ee1

Browse files
authored
Merge pull request syslog-ng#5004 from HofiOne/Add-thread-id-to-evt-logging-in-debug-builds
event-logging: Added automatic logging of the thread_id (with tag thread_id) in each event log message for debug builds
2 parents 4a1edc0 + 4492d0d commit 5a74ee1

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

lib/messages.c

+15
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "messages.h"
2626
#include "timeutils/cache.h"
2727
#include "logmsg/logmsg.h"
28+
#include "thread-utils.h"
2829

2930
#include <stdio.h>
3031
#include <unistd.h>
@@ -35,6 +36,10 @@
3536

3637
#include <evtlog.h>
3738

39+
#if !defined(ADD_THREADID_TAG_TO_EVT_MSGS)
40+
# define ADD_THREADID_TAG_TO_EVT_MSGS 0
41+
#endif
42+
3843
enum
3944
{
4045
/* processing a non-internal message, we're definitely not recursing */
@@ -233,6 +238,16 @@ msg_event_create(gint prio, const gchar *desc, EVTTAG *tag1, ...)
233238

234239
g_mutex_lock(&evtlog_lock);
235240
e = evt_rec_init(evt_context, prio, desc);
241+
242+
/* NOTE: Use ADD_THREADID_TAG_TO_EVT_MSGS during configure to turn on thread_id logging
243+
* Using CMake, it seems to be the only working solution to set it in the env (-D, -e ENv, stc. does not work yet)
244+
* Example:
245+
* CFLAGS="${CFLAGS} -DADD_THREADID_TAG_TO_EVT_MSGS=1" cmake --build build/. --target install -j24 -v
246+
*/
247+
#if ADD_THREADID_TAG_TO_EVT_MSGS && SYSLOG_NG_ENABLE_DEBUG
248+
evt_rec_add_tag(e, evt_tag_long("thread_id", (long) (void *) get_thread_id()));
249+
#endif
250+
236251
if (tag1)
237252
{
238253
evt_rec_add_tag(e, tag1);

0 commit comments

Comments
 (0)