LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-03-2004, 03:26 AM   #1
shellcode
Member
 
Registered: May 2003
Location: Beverly Hills
Distribution: Slackware, Gentoo
Posts: 350

Rep: Reputation: 32
logging


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.

Thanks.
 
Old 10-03-2004, 11:08 AM   #2
aluser
Member
 
Registered: Mar 2004
Location: Massachusetts
Distribution: Debian
Posts: 557

Rep: Reputation: 43
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.
 
Old 10-03-2004, 07:24 PM   #3
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
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...
 
Old 10-06-2004, 01:35 AM   #4
shellcode
Member
 
Registered: May 2003
Location: Beverly Hills
Distribution: Slackware, Gentoo
Posts: 350

Original Poster
Rep: Reputation: 32
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.


Thanks for the replies.
 
Old 10-06-2004, 08:53 AM   #5
aluser
Member
 
Registered: Mar 2004
Location: Massachusetts
Distribution: Debian
Posts: 557

Rep: Reputation: 43
like

Code:
void my_log(int level, const char *fmt, ...);
and the implementation of it could either call syslog or write to a file.
 
Old 10-06-2004, 11:38 AM   #6
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Quote:
Originally posted by aluser
like

Code:
void my_log(int level, const char *fmt, ...);
and the implementation of it could either call syslog or write to a file.
This way it's also easier to implement a command-line option that allows the user to specify if your daemon should log to syslog or its own log-file.
 
Old 10-06-2004, 06:41 PM   #7
shellcode
Member
 
Registered: May 2003
Location: Beverly Hills
Distribution: Slackware, Gentoo
Posts: 350

Original Poster
Rep: Reputation: 32
Ok, thanks. That's what I thought you meant but I wasn't sure.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need Help logging in to 10.0.0.2 ImNew Linux - Networking 1 09-08-2005 09:13 AM
Logging bramhastra Linux - Security 4 05-30-2005 05:28 AM
logging in help dummie_at_linux Linux - Newbie 2 12-29-2004 02:50 PM
logging out spuppett Linux - General 1 03-06-2003 10:27 PM
using red-carpet without logging out and logging as root. packman Linux - Software 1 12-09-2002 02:55 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:18 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration