ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi. I am writing a daemon program (in C, of course). It will run continuously and communicate with unix domain and internet sockets. Like any good daemon, it will do logging. What I am wondering is how I should implement logging.
It would be easy enough for my daemon to read and write to a log file and that would be that. However, I was also thinking about using syslog. Specifically, I would like to know whether using syslog would be good for this type of program. What types of applications use syslog and what types use their own logging format? What are the advantages/disadvantages of using syslog?
The logs will be fairly verbose, and the program should have the ability to cope with a lack of storage space for log files without going down (it'll be running in an embedded system). Does syslog provide this type of capability?
I know this is a pretty vague question, so tell me if I'm not making sense.
If it produces verbose logs, I wouldn't want it to flood my syslog logs -- I'd rather it use a separate file.
Apache uses its own files for its (often very long) access and error logs.
I'm not sure what syslog does in response to being out of space.
In any case, you should probably use a wrapper function so that you can change the details of the logging easily -- then the decision is not such a big deal.
Whether you use syslog or not, you can use the logrotate scripts to set it up to rotate your logs and only keep them for so long. Look at places like /etc/logrotate.conf and scripts in the /etc/logrotate.d directory for examples.
If you use syslog, you could possibly use one of the local syslog facilities and then users could setup their syslog config to go to a separate file if they like by modifying the syslog.conf file. I have something like that setup for the linksys router logging daemon I have running. You could also optionally have a config file or command-line option that lets users specify what facility it logs too. (e.g. LOCAL0 - LOCAL7, DAEMON, etc...)
I'm not saying that syslog is definitely the way to go, just giving some options on what you could do if you did use syslog. The logrotate stuff works with any log files, not just syslogs, so whatever you go with, you can use that. It might not be obvious to people installing the daemon that they would need to do that, though...
aluser: What exactly do you mean by wrapper function?
deiussum: Thanks, I'll look into logrotate. Since syslog is pretty powerful and it can log to other files when told to, I think I'll probably use that.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.