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