6749N/A<?
xml version='1.0'?>
<!--*-nxml-*--> 6749N/A<!
DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" 6749N/A This file is part of systemd. 6749N/A Copyright 2012 Lennart Poettering 6749N/A systemd is free software; you can redistribute it and/or modify it 6749N/A under the terms of the GNU Lesser General Public License as published by 6749N/A the Free Software Foundation; either version 2.1 of the License, or 6749N/A (at your option) any later version. 6749N/A systemd is distributed in the hope that it will be useful, but 6749N/A WITHOUT ANY WARRANTY; without even the implied warranty of 6749N/A MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 6749N/A Lesser General Public License for more details. 6749N/A You should have received a copy of the GNU Lesser General Public License 6749N/A<
refentry id="sd_journal_stream_fd">
6749N/A <
title>sd_journal_stream_fd</
title>
6749N/A <
productname>systemd</
productname>
6749N/A <
contrib>Developer</
contrib>
6749N/A <
firstname>Lennart</
firstname>
6749N/A <
surname>Poettering</
surname>
6749N/A <
email>lennart@poettering.net</
email>
6749N/A <
refentrytitle>sd_journal_stream_fd</
refentrytitle>
6749N/A <
refname>sd_journal_stream_fd</
refname>
6749N/A <
refpurpose>Create log stream file descriptor to the journal</
refpurpose>
<
funcdef>int <
function>sd_journal_stream_fd</
function></
funcdef>
<
paramdef>const char* <
parameter>identifier</
parameter></
paramdef>
<
paramdef>int <
parameter>priority</
parameter></
paramdef>
<
paramdef>int <
parameter>level_prefix</
parameter></
paramdef>
<
title>Description</
title>
<
para><
function>sd_journal_stream_fd()</
function> 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
processes executed.</
para>
<
para><
function>sd_journal_stream_fd()</
function>
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
for more information). The second argument shall be
the default priority level for all messages. The
priority level is one of <
literal>LOG_EMERG</
literal>,
<
literal>LOG_ALERT</
literal>,
<
literal>LOG_CRIT</
literal>,
<
literal>LOG_ERR</
literal>,
<
literal>LOG_WARNING</
literal>,
<
literal>LOG_NOTICE</
literal>,
<
literal>LOG_INFO</
literal>,
<
literal>LOG_DEBUG</
literal>, as defined in
<
citerefentry><
refentrytitle>syslog</
refentrytitle><
manvolnum>3</
manvolnum></
citerefentry>
for details. The third argument is a boolean: if true
kernel-style log priority level prefixes (such as
<
literal>SD_WARNING</
literal>) are interpreted, see
<
citerefentry><
refentrytitle>sd-daemon</
refentrytitle><
manvolnum>3</
manvolnum></
citerefentry>
for more information.</
para>
<
para>It is recommended that applications log UTF-8
mesages only with this API, but this is not
<
title>Return Value</
title>
<
para>The call returns a valid write-only file descriptor on success or a
negative errno-style error code.</
para>
<
para>The <
function>sd_journal_stream_fd()</
function>
interface is available as shared library, which can
be compiled and linked to with the
<
literal>libsystemd-journal</
literal>
<
citerefentry><
refentrytitle>pkg-config</
refentrytitle><
manvolnum>1</
manvolnum></
citerefentry>
<
para>Creating a log stream suitable for
<
citerefentry><
refentrytitle>fprintf</
refentrytitle><
manvolnum>3</
manvolnum></
citerefentry>:</
para>
<
programlisting>#include <
syslog.h>
int main(int argc, char *argv[]) {
fd = sd_journal_stream_fd("test", LOG_INFO, 1);
fprintf(stderr, "Failed to create stream fd: %s\n", strerror(-fd));
fprintf(stderr, "Failed to create file object: %m\n");
fprintf(log, "Hello World!\n");
fprintf(log, SD_WARNING "This is a warning!\n");
<
citerefentry><
refentrytitle>systemd</
refentrytitle><
manvolnum>1</
manvolnum></
citerefentry>,
<
citerefentry><
refentrytitle>sd-journal</
refentrytitle><
manvolnum>3</
manvolnum></
citerefentry>,
<
citerefentry><
refentrytitle>sd-daemon</
refentrytitle><
manvolnum>3</
manvolnum></
citerefentry>,
<
citerefentry><
refentrytitle>sd_journal_print</
refentrytitle><
manvolnum>3</
manvolnum></
citerefentry>,
<
citerefentry><
refentrytitle>syslog</
refentrytitle><
manvolnum>3</
manvolnum></
citerefentry>,
<
citerefentry><
refentrytitle>fprintf</
refentrytitle><
manvolnum>3</
manvolnum></
citerefentry>,