Sponsored Content
Full Discussion: Syslog in C
Top Forums UNIX for Dummies Questions & Answers Syslog in C Post 302510399 by achenle on Sunday 3rd of April 2011 05:04:55 PM
Old 04-03-2011
If this is a long-lived process that you don't want to have tied to its log file, you do need to use something like syslog.

By having a direct open file descriptor on your log file, your process needs to handle log roll over directly, the log file can not be deleted or moved to another file system without your process having code to handle that. That code already exists in syslog, so you're just reinventing the wheel.

And don't ever use redirected stdout and/or stderr for log files for long-lived daemon processes. What are you going to do when this:

Code:
MyProcessd > /my/log/file.log &

fills up a disk?

About the only thing you CAN do in that situation is kill your daemon.
 

2 More Discussions You Might Find Interesting

1. Solaris

Which are the available entries to forward syslog in syslog.conf?

Hi Community Which are the available entries to forward syslog in syslog.conf i have put *.err;kern.debug;daemon.notice;mail.crit;user.alert;user.emerg;kern.notice;auth.notice;kern.warning @172.16.200.50 and it's not going through.giving error message like below: syslogd:... (2 Replies)
Discussion started by: bentech4u
2 Replies

2. AIX

Cannot send syslog event from AIX 6.1 to RHEL Syslog server

Hi everyone, I am trying to configure AIX 6.1 using syslogd to send syslog event to syslog server configured on RHEL. However, RHEL never receives the events. I have tried to redirect the syslog event on AIX to a local file and successful. Only forwarding to remote server fails. Firewall... (10 Replies)
Discussion started by: michael_hoang
10 Replies
SD_JOURNAL_STREAM_FD(3) 				       sd_journal_stream_fd					   SD_JOURNAL_STREAM_FD(3)

NAME
sd_journal_stream_fd - Create log stream file descriptor to the journal SYNOPSIS
#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-fields(7) 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 syslog(3) for details. The third argument is a boolean: if true kernel-style log priority level prefixes (such as SD_WARNING) are interpreted, see sd-daemon(3) for more information. It is recommended that applications log UTF-8 messages 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 a shared library, which can be compiled and linked to with the libsystemd-journal pkg- config(1) file. EXAMPLES
Creating a log stream suitable for fprintf(3): #include <syslog.h> #include <stdio.h> #include <string.h> #include <unistd.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 ", strerror(-fd)); return 1; } log = fdopen(fd, "w"); if (!log) { fprintf(stderr, "Failed to create file object: %m "); close(fd); return 1; } fprintf(log, "Hello World! "); fprintf(log, SD_WARNING "This is a warning! "); fclose(log); return 0; } SEE ALSO
systemd(1), sd-journal(3), sd-daemon(3), sd_journal_print(3), syslog(3), fprintf(3), systemd.journal-fields(7) systemd 208 SD_JOURNAL_STREAM_FD(3)
All times are GMT -4. The time now is 08:25 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy