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. Note that log
32       messages written using this function are generally not expected to end
33       in a new-line character. However, as all trailing whitespace (including
34       spaces, new-lines, tabulators and carriage returns) are automatically
35       stripped from the logged string, it is acceptable to specify one (or
36       more). Empty lines (after trailing whitespace removal) are suppressed.
37       On non-empty lines, leading whitespace (as well as inner whitespace) is
38       left unmodified.
39
40       sd_journal_printv() is similar to sd_journal_print() but takes a
41       variable argument list encapsulated in an object of type va_list (see
42       stdarg(3) for more information) instead of the format string. It is
43       otherwise equivalent in behavior.
44
45       sd_journal_send() may be used to submit structured log entries to the
46       system journal. It takes a series of format strings, each immediately
47       followed by their associated parameters, terminated by NULL. The
48       strings passed should be of the format "VARIABLE=value". The variable
49       name must be in uppercase and consist only of characters, numbers and
50       underscores, and may not begin with an underscore. (All assignments
51       that do not follow this syntax will be ignored.) The value can be of
52       any size and format. It is highly recommended to submit text strings
53       formatted in the UTF-8 character encoding only, and submit binary
54       fields only when formatting in UTF-8 strings is not sensible. A number
55       of well-known fields are defined, see systemd.journal-fields(7) for
56       details, but additional application defined fields may be used. A
57       variable may be assigned more than one value per entry. If this
58       function is used, trailing whitespace is automatically removed from
59       each formatted field.
60
61       sd_journal_sendv() is similar to sd_journal_send() but takes an array
62       of struct iovec (as defined in uio.h, see readv(3) for details) instead
63       of the format string. Each structure should reference one field of the
64       entry to submit. The second argument specifies the number of structures
65       in the array.  sd_journal_sendv() is particularly useful to submit
66       binary objects to the journal where that is necessary. Note that this
67       function will not strip trailing whitespace of the passed fields, but
68       passes the specified data along unmodified. This is different from both
69       sd_journal_print() and sd_journal_send() described above, which are
70       based on format strings, and do strip trailing whitespace.
71
72       sd_journal_perror() is a similar to perror(3) and writes a message to
73       the journal that consists of the passed string, suffixed with ": " and
74       a human-readable representation of the current error code stored in
75       errno(3). If the message string is passed as NULL or empty string, only
76       the error string representation will be written, prefixed with nothing.
77       An additional journal field ERRNO= is included in the entry containing
78       the numeric error code formatted as decimal string. The log priority
79       used is LOG_ERR (3).
80
81       Note that sd_journal_send() is a wrapper around sd_journal_sendv() to
82       make it easier to use when only text strings shall be submitted. Also,
83       the following two calls are mostly equivalent:
84
85           sd_journal_print(LOG_INFO, "Hello World, this is PID %lu!", (unsigned long) getpid());
86
87           sd_journal_send("MESSAGE=Hello World, this is PID %lu!", (unsigned long) getpid(),
88                           "PRIORITY=%i", LOG_INFO,
89                           NULL);
90
91       Note that these calls implicitly add fields for the source file,
92       function name and code line where invoked. This is implemented with
93       macros. If this is not desired, it can be turned off by defining
94       SD_JOURNAL_SUPPRESS_LOCATION before including sd-journal.h.
95
96       syslog(3) and sd_journal_print() may largely be used interchangeably
97       functionality-wise. However, note that log messages logged via the
98       former take a different path to the journal server than the later, and
99       hence global chronological ordering between the two streams cannot be
100       guaranteed. Using sd_journal_print() has the benefit of logging source
101       code line, filenames, and functions as metadata along all entries, and
102       guaranteeing chronological ordering with structured log entries that
103       are generated via sd_journal_send(). Using syslog() has the benefit of
104       being more portable.
105

RETURN VALUE

107       The five calls return 0 on success or a negative errno-style error
108       code. The errno(3) variable itself is not altered.
109
110       If systemd-journald(8) is not running (the socket is not present),
111       those functions do nothing, and also return 0.
112

THREAD SAFETY

114       All functions listed here are thread-safe and may be called in parallel
115       from multiple threads.
116
117       sd_journal_sendv() is "async signal safe" in the meaning of signal-
118       safety(7).
119
120       sd_journal_print, sd_journal_printv, sd_journal_send, and
121       sd_journal_perror are not async signal safe.
122

NOTES

124       These APIs are implemented as a shared library, which can be compiled
125       and linked to with the libsystemd pkg-config(1) file.
126

SEE ALSO

128       systemd(1), sd-journal(3), sd_journal_stream_fd(3), syslog(3),
129       perror(3), errno(3), systemd.journal-fields(7), signal(7), socket(7)
130
131
132
133systemd 241                                                SD_JOURNAL_PRINT(3)
Impressum