From: Lennart Poettering Date: Fri, 13 Jul 2012 00:18:45 +0000 (+0200) Subject: man: document sd_journal_stream_fd() X-Git-Tag: v187~112 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=commitdiff_plain;h=a81df0ad90f0dea0eb272c02efe18934fa66fdf2 man: document sd_journal_stream_fd() --- diff --git a/Makefile.am b/Makefile.am index a06b0ca6a..52d78e657 100644 --- a/Makefile.am +++ b/Makefile.am @@ -499,7 +499,8 @@ MANPAGES = \ man/sd_id128_to_string.3 \ man/sd_id128_randomize.3 \ man/sd-journal.3 \ - man/sd_journal_print.3 + man/sd_journal_print.3 \ + man/sd_journal_stream_fd.3 MANPAGES_ALIAS = \ man/reboot.8 \ diff --git a/man/sd_journal_stream_fd.xml b/man/sd_journal_stream_fd.xml new file mode 100644 index 000000000..3d2ed1d8f --- /dev/null +++ b/man/sd_journal_stream_fd.xml @@ -0,0 +1,168 @@ + + + + + + + + + sd_journal_stream_fd + systemd + + + + Developer + Lennart + Poettering + lennart@poettering.net + + + + + + sd_journal_stream_fd + 3 + + + + sd_journal_stream_fd + Create log stream file descriptor to the journal + + + + + #include <systemd/sd-journal.h> + + + int sd_journal_stream_fd + const char* identifier + int priority + int level_prefix + + + + + + + Description + + sd_journal_stream_fd() may + be used to create a log stream file descriptor. Log + messages written to this file descriptor as simple + newline separated text strings are written to the + journal. This file descriptor can be used internally + by applications or be made STDOUT/STDERR of other + processes executed. + + sd_journal_stream_fd() + takes a short program identifier string as first + argument, which will be written to the journal as + _SYSLOG_IDENTIFIER= field for each log entry (see + systemd.journal-fields7 + for more information). The second argument shall be + the default priority level for all messages. The + priority level is one of LOG_EMERG, + LOG_ALERT, + LOG_CRIT, + LOG_ERR, + LOG_WARNING, + LOG_NOTICE, + LOG_INFO, + LOG_DEBUG, as defined in + syslog.h, see + syslog3 + for details. The third argument is a boolean: if true + kernel-style log priority level prefixes (such as + SD_WARNING) are interpreted, see + sd-daemon3 + for more information. + + It is recommended that applications log UTF-8 + mesages only with this API, but this is not + enforced. + + + + + Return Value + + The call returns a valid write-only file descriptor on success or a + negative errno-style error code. + + + + Notes + + The sd_journal_stream_fd() + interface is available as shared library, which can + be compiled and linked to with the + libsystemd-journal + pkg-config1 + file. + + + + Examples + + Creating a log stream suitable for + fprintf3: + + #include <syslog.h> +#include <stdio.h> +#include <systemd/sd-journal.h> +#include <systemd/sd-daemon.h> + +int main(int argc, char *argv[]) { + int fd; + FILE *log; + fd = sd_journal_stream_fd("test", LOG_INFO, 1); + if (fd < 0) { + fprintf(stderr, "Failed to create stream fd: %s\n", strerror(-fd)); + return 1; + } + log = fdopen(fd, "w"); + if (!log) { + fprintf(stderr, "Failed to create file object: %m\n"); + close(fd); + return 1; + } + fprintf(log, "Hello World!\n"); + fprintf(log, SD_WARNING "This is a warning!\n"); + fclose(log); +} + + + + + See Also + + + systemd1, + sd-journal3, + sd-daemon3, + sd_journal_print3, + syslog3, + fprintf3, + systemd.journal-fields7 + + + + diff --git a/src/systemd/sd-journal.h b/src/systemd/sd-journal.h index cf1b8db74..935b0452b 100644 --- a/src/systemd/sd-journal.h +++ b/src/systemd/sd-journal.h @@ -129,8 +129,8 @@ int sd_journal_wait(sd_journal *j, uint64_t timeout_usec); #define SD_JOURNAL_FOREACH_DATA(j, data, l) \ for (sd_journal_restart_data(j); sd_journal_enumerate_data((j), &(data), &(l)) > 0; ) -#define SD_JOURNAL_FOREACH_UNIQUE(j, data, l) \ - for (sd_journal_restart_unique(j); sd_journal_enumerate_data((j), &(data), &(l)) > 0; ) +/* #define SD_JOURNAL_FOREACH_UNIQUE(j, data, l) \ */ +/* for (sd_journal_restart_unique(j); sd_journal_enumerate_data((j), &(data), &(l)) > 0; ) */ #ifdef __cplusplus }