8 tracelog - LTTng-UST printf(3)-like interface with a log level
14 *#include <lttng/tracelog.h>*
17 #define *tracelog*('level', 'fmt', ...)
19 Link with `-llttng-ust`.
24 The LTTng-UST `tracelog()` API allows you to trace your application with
25 the help of a simple man:printf(3)-like macro, with an additional
26 parameter for the desired log level. The 'fmt' argument is passed
27 directly to the 'fmt' parameter of man:vasprintf(3), as well as
28 the optional parameters following 'fmt'.
30 The purpose of `tracelog()` is to ease the migration from logging to
33 The available values for the 'level' parameter are:
35 include::log-levels.txt[]
37 To use `tracelog()`, include `<lttng/tracelog.h>` where you need it, and
38 link your application with `liblttng-ust`. See the <<example,EXAMPLE>>
39 section below for a complete usage example.
41 Once your application is instrumented with `tracelog()` calls and
42 ready to run, use man:lttng-enable-event(1) to enable the
43 `lttng_ust_tracelog:*` event. You can isolate specific log levels with
44 the nloption:--loglevel and nloption:--loglevel-only options of this
47 The `tracelog()` events contain the following fields:
51 |Field name |Description
54 |Line in source file where `tracelog()` was called
57 |Source file from which `tracelog()` was called
60 |Function name from which `tracelog()` was called
63 |Formatted string output
66 If you do not need to attach a specific log level to a `tracelog()`
67 call, use man:tracef(3) instead.
69 See also the <<limitations,LIMITATIONS>> section below for important
70 limitations to consider when using `tracelog()`.
76 Here's a usage example of `tracelog()`:
78 -------------------------------------------------------------------
80 #include <lttng/tracelog.h>
82 int main(int argc, char *argv[])
87 tracelog(TRACE_CRIT, "Not enough arguments: %d", argc);
91 tracelog(TRACE_INFO, "Starting app with %d arguments", argc);
93 for (i = 0; i < argc; i++) {
94 tracelog(TRACE_DEBUG, "Argument %d: %s", i, argv[i]);
97 tracelog(TRACE_INFO, "Exiting app");
101 -------------------------------------------------------------------
103 This C source file, saved as `app.c`, can be compiled into a program
107 ---------------------------
108 cc -o app app.c -llttng-ust
109 ---------------------------
111 You can create an LTTng tracing session, enable all the `tracelog()`
112 events, and start the created tracing session like this:
115 ---------------------------------------------------
116 lttng create my-session
117 lttng enable-event --userspace 'lttng_ust_tracelog:*'
119 ---------------------------------------------------
121 Or you can enable `tracelog()` events matching a log level at least
122 as severe as a given log level:
125 -------------------------------------------------------
126 lttng enable-event --userspace 'lttng_ust_tracelog:*' \
127 --loglevel=TRACE_INFO
128 -------------------------------------------------------
130 Next, start the program to be traced:
133 ------------------------------------------------
134 ./app a few arguments passed to this application
135 ------------------------------------------------
137 Finally, stop the tracing session, and inspect the recorded events:
149 :macro-name: tracelog
151 include::tracef-tracelog-limitations.txt[]
154 include::common-footer.txt[]
156 include::common-copyrights.txt[]
158 include::common-authors.txt[]