Document tracelog() facility
[lttng-docs.git] / contents / using-lttng / instrumenting / c-application / tracelog.md
1 ---
2 id: tracelog
3 since: 2.7
4 ---
5
6 The `tracelog()` API is very similar to [`tracef()`](#doc-tracef). The
7 only difference is that it accepts an additional log level parameter.
8
9 The goal of `tracelog()` is to ease the migration from logging to
10 tracing.
11
12 Here's an example:
13
14 ~~~ c
15 #include <lttng/tracelog.h>
16
17 void my_function(int my_integer) {
18 /* ... */
19
20 tracelog(TRACE_INFO, "my message, my integer: %d", my_integer);
21
22 /* ... */
23 }
24 ~~~
25
26 See [LTTng-UST library reference](#doc-liblttng-ust-tracepoint-loglevel)
27 for the list of available log level names.
28
29 Link your application with `liblttng-ust`:
30
31 <pre class="term">
32 gcc -o app app.c <strong>-llttng-ust</strong>
33 </pre>
34
35 Execute the application as usual:
36
37 <pre class="term">
38 ./app
39 </pre>
40
41 The events produced by `tracelog()` calls are prefixed with
42 `lttng_ust_tracelog:`. To enable `tracelog()` events matching a range
43 of log levels, do:
44
45 <pre class="term">
46 lttng enable-event --userspace 'lttng_ust_tracelog:*' \
47 --loglevel TRACE_INFO
48 </pre>
49
50 This enables all `tracelog()` events with a log level at least as important
51 as `TRACE_INFO`.
52
53 To enable `tracelog()` events matching a specific log level, do:
54
55 <pre class="term">
56 lttng enable-event --userspace 'lttng_ust_tracelog:*' \
57 --loglevel-only TRACE_WARNING
58 </pre>
59
60 See [Enabling and disabling events](#doc-enabling-disabling-events) for
61 more options.
This page took 0.031652 seconds and 4 git commands to generate.