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