8 tracelog - LTTng-UST printf(3)-like interface with a log level
14 *#include <lttng/tracelog.h>*
17 #define *tracelog*('level', 'fmt', ...)
18 #define *vtracelog*('level', 'fmt', 'va_list' ap)
20 Link with `-llttng-ust`.
25 The LTTng-UST `tracelog()` API allows you to trace your application with
26 the help of a simple man:printf(3)-like macro, with an additional
27 parameter for the desired log level. The 'fmt' argument is passed
28 directly to the 'fmt' parameter of man:vasprintf(3), as well as
29 the optional parameters following 'fmt'.
31 The purpose of `tracelog()` is to ease the migration from logging to
34 The available values for the 'level' parameter are:
36 include::log-levels.txt[]
38 To use `tracelog()` or `vtracelog()`, include `<lttng/tracelog.h>` where you
39 need it, and link your application with `liblttng-ust`.
40 See the <<example,EXAMPLE>> section below for a complete usage example.
42 Once your application is instrumented with `tracelog()` calls and
43 ready to run, use man:lttng-enable-event(1) to enable the
44 `lttng_ust_tracelog:*` event. You can isolate specific log levels with
45 the nloption:--loglevel and nloption:--loglevel-only options of this
48 The `tracelog()` events contain the following fields:
52 |Field name |Description
55 |Line in source file where `tracelog()` was called.
58 |Source file from which `tracelog()` was called.
61 |Function name from which `tracelog()` was called.
64 |Formatted string output.
67 If you do not need to attach a specific log level to a `tracelog()`
68 call, use man:tracef(3) instead.
70 See also the <<limitations,LIMITATIONS>> section below for important
71 limitations to consider when using `tracelog()` or `vtracelog()`.
77 Here's a usage example of `tracelog()`:
79 -------------------------------------------------------------------
81 #include <lttng/tracelog.h>
83 int main(int argc, char *argv[])
88 tracelog(TRACE_CRIT, "Not enough arguments: %d", argc);
92 tracelog(TRACE_INFO, "Starting app with %d arguments", argc);
94 for (i = 0; i < argc; i++) {
95 tracelog(TRACE_DEBUG, "Argument %d: %s", i, argv[i]);
98 tracelog(TRACE_INFO, "Exiting app");
102 -------------------------------------------------------------------
104 This C source file, saved as `app.c`, can be compiled into a program
109 $ cc -o app app.c -llttng-ust
112 You can create an LTTng tracing session, enable all the `tracelog()`
113 events, and start the created tracing session like this:
117 $ lttng create my-session
118 $ lttng enable-event --userspace 'lttng_ust_tracelog:*'
122 Or you can enable `tracelog()` events matching a log level at least
123 as severe as a given log level:
127 $ lttng enable-event --userspace 'lttng_ust_tracelog:*' \
128 --loglevel=TRACE_INFO
131 Next, start the program to be traced:
135 $ ./app a few arguments passed to this application
138 Finally, stop the tracing session, and inspect the recorded events:
150 :macro-name: tracelog
152 include::tracef-tracelog-limitations.txt[]
155 include::common-footer.txt[]
157 include::common-copyrights.txt[]
159 include::common-authors.txt[]