4

I have been reading about how to keep error/warning logs of a C program on Linux environment. Is it better to write the errno to a file as it is done here or is it better to use syslog or setlogmask system calls or another method? I would appreciate an answer with an example code.

1
  • Notice that syslog is not a system call (which are listed in syscalls(2) man page). Commented Apr 29, 2013 at 9:31

2 Answers 2

3

I would strongly suggest using syslog for logging errors as its more standard way of logging.

you can look at the example implemenation here (bio3d.colorado.edu/tor/sadocs/misc/syslog.html)

Also unix network programming book by richard stevens also contains good explanation of using syslog

Sign up to request clarification or add additional context in comments.

Comments

2

The above link no longer works - try this one here: https://www.gnu.org/software/libc/manual/html_node/Syslog-Example.html#Syslog-Example

....which contains the following example:

#include <syslog.h> setlogmask (LOG_UPTO (LOG_NOTICE)); openlog ("exampleprog", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1); syslog (LOG_NOTICE, "Program started by User %d", getuid ()); syslog (LOG_INFO, "A tree falls in a forest"); closelog (); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.