Syslog in C


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Syslog in C
# 1  
Old 04-03-2011
Syslog in C

Hey, I'm pretty new to C programming in a Linux environment and was wondering if I could get some help using log files. What I want to do is have my program write data to a log file (like /var/log/motord or something like that where a new file is being created) but I'm having a surprising amount of trouble figuring out how to go about this. Could someone perhaps post some example code that would do this sort of thing?

Also, is there a way to write a program that would, while it's running, print the lines that are being added to the log fill to the command prompt? Only while the program is running though and only the lines that are actively being sent, not the entire file. This is more of an after thought but I'm not really sure where to start with that either or if it's something that's even doable.

Just as a reference as well, these programs will be running on a remote system and I plan on accessing the command prompt via telnet. This really only affects the latter situation but I figured it would be good to specify.

Any help would be great. Thanks in advance Smilie
# 2  
Old 04-03-2011
/etc/syslog.conf determines what gets written to syslog. Try man syslog.conf

I am guessing you do not want syslog() at all. This is because you want to write to another file. Do you want messages also to appear on the console?
# 3  
Old 04-03-2011
I would like messages to appear on the console only when I am looking for them which is why I mentioned the possible program in the second paragraph of my initial post. And I did start to get the impression that syslog() wasn't going to work. I just liked the idea that it would add all of the tags to the beginning of each line, most notably the time. Would an fprintf() or something like that make more sense though?
# 4  
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.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

2 More Discussions You Might Find Interesting

1. 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

2. 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
Login or Register to Ask a Question