lttng-ust(3): sort ctf_*() macro parameter definitions
[lttng-ust.git] / doc / man / tracelog.3.txt
CommitLineData
4ddbd0b7
PP
1tracelog(3)
2===========
3:object-type: macro
4
5
6NAME
7----
0810c65b 8tracelog - LTTng-UST printf(3)-like interface with a log level
4ddbd0b7
PP
9
10
11SYNOPSIS
12--------
13[verse]
14*#include <lttng/tracelog.h>*
15
16[verse]
17#define *tracelog*('level', 'fmt', ...)
18
19Link with `-llttng-ust`.
20
21
22DESCRIPTION
23-----------
24The LTTng-UST `tracelog()` API allows you to trace your application with
25the help of a simple man:printf(3)-like macro, with an additional
26parameter for the desired log level. The 'fmt' argument is passed
27directly to the 'fmt' parameter of man:vasprintf(3), as well as
28the optional parameters following 'fmt'.
29
30The purpose of `tracelog()` is to ease the migration from logging to
31tracing.
32
33The available values for the 'level' parameter are:
34
35include::log-levels.txt[]
36
37To use `tracelog()`, include `<lttng/tracelog.h>` where you need it, and
38link your application with `liblttng-ust`. See the <<example,EXAMPLE>>
39section below for a complete usage example.
40
41Once your application is instrumented with `tracelog()` calls and
42ready to run, use man:lttng-enable-event(1) to enable the
43`lttng_ust_tracelog:*` event. You can isolate specific log levels with
44the nloption:--loglevel and nloption:--loglevel-only options of this
45command.
46
47The `tracelog()` events contain the following fields:
48
49[options="header"]
50|===============================================================
51| Field name | Description
52| `line` | Line in source file where `tracelog()` was called
53| `file` | Source file from which `tracelog()` was called
54| `func` | Function name from which `tracelog()` was called
55| `msg` | Formatted string output
56|===============================================================
57
58If you do not need to attach a specific log level to a `tracelog()`
59call, use man:tracef(3) instead.
60
61See also the <<limitations,LIMITATIONS>> section below for important
62limitations to consider when using `tracelog()`.
63
64
65[[example]]
66EXAMPLE
67-------
68Here's a usage example of `tracelog()`:
69
70-------------------------------------------------------------------
71#include <stdlib.h>
72#include <lttng/tracelog.h>
73
74int main(int argc, char *argv[])
75{
76 int i;
77
78 if (argc < 2) {
79 tracelog(TRACE_CRIT, "Not enough arguments: %d", argc);
80 return EXIT_FAILURE;
81 }
82
83 tracelog(TRACE_INFO, "Starting app with %d arguments", argc);
84
85 for (i = 0; i < argc; i++) {
86 tracelog(TRACE_DEBUG, "Argument %d: %s", i, argv[i]);
87 }
88
89 tracelog(TRACE_INFO, "Exiting app");
90
91 return EXIT_SUCCESS;
92}
93-------------------------------------------------------------------
94
95This C source file, saved as `app.c`, can be compiled into a program
96like this:
97
98[role="term"]
99---------------------------
100cc -o app app.c -llttng-ust
101---------------------------
102
103You can create an LTTng tracing session, enable all the `tracelog()`
104events, and start the created tracing session like this:
105
106[role="term"]
107---------------------------------------------------
108lttng create my-session
109lttng enable-event --userspace 'lttng_ust_tracelog:*'
110lttng start
111---------------------------------------------------
112
113Or you can enable `tracelog()` events matching a log level at least
114as severe as a given log level:
115
116[role="term"]
117-------------------------------------------------------
118lttng enable-event --userspace 'lttng_ust_tracelog:*' \
119 --loglevel=TRACE_INFO
120-------------------------------------------------------
121
122Next, start the program to be traced:
123
124[role="term"]
125------------------------------------------------
126./app a few arguments passed to this application
127------------------------------------------------
128
129Finally, stop the tracing session, and inspect the recorded events:
130
131[role="term"]
132----------
133lttng stop
134lttng view
135----------
136
137
138[[limitations]]
139LIMITATIONS
140-----------
141:macro-name: tracelog
142
143include::tracef-tracelog-limitations.txt[]
144
145
146include::common-footer.txt[]
147
148include::common-copyrights.txt[]
149
150include::common-authors.txt[]
151
152
153SEE ALSO
154--------
155man:tracef(3),
156man:lttng-ust(3),
157man:lttng(1),
158man:printf(3)
This page took 0.027566 seconds and 4 git commands to generate.