1SD_JOURNAL_PRINT(3)            sd_journal_print            SD_JOURNAL_PRINT(3)
2
3
4

NAME

6       sd_journal_print, sd_journal_printv, sd_journal_send, sd_journal_sendv,
7       sd_journal_perror, SD_JOURNAL_SUPPRESS_LOCATION - Submit log entries to
8       the journal
9

SYNOPSIS

11       #include <systemd/sd-journal.h>
12
13       int sd_journal_print(int priority, const char *format, ...);
14
15       int sd_journal_printv(int priority, const char *format, va_list ap);
16
17       int sd_journal_send(const char *format, ...);
18
19       int sd_journal_sendv(const struct iovec *iov, int n);
20
21       int sd_journal_perror(const char *message);
22

DESCRIPTION

24       sd_journal_print() may be used to submit simple, plain text log entries
25       to the system journal. The first argument is a priority value. This is
26       followed by a format string and its parameters, similar to printf(3) or
27       syslog(3). The priority value is one of LOG_EMERG, LOG_ALERT, LOG_CRIT,
28       LOG_ERR, LOG_WARNING, LOG_NOTICE, LOG_INFO, LOG_DEBUG, as defined in
29       syslog.h, see syslog(3) for details. It is recommended to use this call
30       to submit log messages in the application locale or system locale and
31       in UTF-8 format, but no such restrictions are enforced.
32
33       sd_journal_printv() is similar to sd_journal_print() but takes a
34       variable argument list encapsulated in an object of type va_list (see
35       stdarg(3) for more information) instead of the format string. It is
36       otherwise equivalent in behavior.
37
38       sd_journal_send() may be used to submit structured log entries to the
39       system journal. It takes a series of format strings, each immediately
40       followed by their associated parameters, terminated by NULL. The
41       strings passed should be of the format "VARIABLE=value". The variable
42       name must be in uppercase and consist only of characters, numbers and
43       underscores, and may not begin with an underscore. (All assignments
44       that do not follow this syntax will be ignored.) The value can be of
45       any size and format. It is highly recommended to submit text strings
46       formatted in the UTF-8 character encoding only, and submit binary
47       fields only when formatting in UTF-8 strings is not sensible. A number
48       of well known fields are defined, see systemd.journal-fields(7) for
49       details, but additional application defined fields may be used. A
50       variable may be assigned more than one value per entry.
51
52       sd_journal_sendv() is similar to sd_journal_send() but takes an array
53       of struct iovec (as defined in uio.h, see readv(3) for details) instead
54       of the format string. Each structure should reference one field of the
55       entry to submit. The second argument specifies the number of structures
56       in the array.  sd_journal_sendv() is particularly useful to submit
57       binary objects to the journal where that is necessary.
58
59       sd_journal_perror() is a similar to perror(3) and writes a message to
60       the journal that consists of the passed string, suffixed with ": " and
61       a human readable representation of the current error code stored in
62       errno(3). If the message string is passed as NULL or empty string, only
63       the error string representation will be written, prefixed with nothing.
64       An additional journal field ERRNO= is included in the entry containing
65       the numeric error code formatted as decimal string. The log priority
66       used is LOG_ERR (3).
67
68       Note that sd_journal_send() is a wrapper around sd_journal_sendv() to
69       make it easier to use when only text strings shall be submitted. Also,
70       the following two calls are mostly equivalent:
71
72           sd_journal_print(LOG_INFO, "Hello World, this is PID %lu!", (unsigned long) getpid());
73
74           sd_journal_send("MESSAGE=Hello World, this is PID %lu!", (unsigned long) getpid(),
75               "PRIORITY=%i", LOG_INFO,
76               NULL);
77
78       Note that these calls implicitly add fields for the source file,
79       function name and code line where invoked. This is implemented with
80       macros. If this is not desired, it can be turned off by defining
81       SD_JOURNAL_SUPPRESS_LOCATION before including sd-journal.h.
82
83       syslog(3) and sd_journal_print() may largely be used interchangeably
84       functionality-wise. However, note that log messages logged via the
85       former take a different path to the journal server than the later, and
86       hence global chronological ordering between the two streams cannot be
87       guaranteed. Using sd_journal_print() has the benefit of logging source
88       code line, filenames, and functions as metadata along all entries, and
89       guaranteeing chronological ordering with structured log entries that
90       are generated via sd_journal_send(). Using syslog() has the benefit of
91       being more portable.
92

RETURN VALUE

94       The four calls return 0 on success or a negative errno-style error
95       code. The errno(3) variable itself is not altered.
96
97       If systemd-journald(8) is not running (the socket is not present),
98       those functions do nothing, and also return 0.
99

ASYNC SIGNAL SAFETY

101       sd_journal_sendv() is "async signal safe" in the meaning of signal(7).
102
103       sd_journal_print, sd_journal_printv, sd_journal_send, and
104       sd_journal_perror are not async signal safe.
105

NOTES

107       The sd_journal_print(), sd_journal_printv(), sd_journal_send() and
108       sd_journal_sendv() interfaces are available as a shared library, which
109       can be compiled and linked to with the libsystemd pkg-config(1) file.
110

SEE ALSO

112       systemd(1), sd-journal(3), sd_journal_stream_fd(3), syslog(3),
113       perror(3), errno(3), systemd.journal-fields(7), signal(7), socket(7)
114
115
116
117systemd 219                                                SD_JOURNAL_PRINT(3)
Impressum