newbie: C-Program write to /var/log/mylog via syslog
I have a C program I am writing and need this program to write to syslog and have the logs in a separate file for my program.
Eg. My program is called "example.c", then I want to have a log file called "example.log" in /var/log. Do I define log file "example.log"in syslogd.conf file?
Or have the C-Program to write to this file via syslog?
I want to have the message in the format yyyy/mm/dd 24HR:MM:SS LOG_TYPE: MESSAGE
I need to have date and time in format yyyy/mm/dd 24HR:MM:SS. Log_type is an severity of error. and MESSAGE is acutal error message.
Any suggestions in doing this in C?
jobs
Junior Poster in Training
58 posts since Jan 2007
Reputation Points: 10
Solved Threads: 0
Do you really want your operating system to do the logging? Or do you only need a file created with log entries in it?
WaltP
Posting Sage w/ dash of thyme
10,492 posts since May 2006
Reputation Points: 3,348
Solved Threads: 943
WaltP I am pretty curious to know now, how would you make OS to log things for. As far i know it should have done by programmer itself isn't Or... am i going wrong somewhere
Only in your explanation. You said "I have a C program I am writing and need this program to write to syslog..." Syslog means system log, the log file for the system and I was simply wondering if you really meant what you said.
When you need to log a message, call a function that uses sprintf() to put the message together. Open the file, write the message, close the file.
WaltP
Posting Sage w/ dash of thyme
10,492 posts since May 2006
Reputation Points: 3,348
Solved Threads: 943
Do you really want your operating system to do the logging? Or do you only need a file created with log entries in it?
I just want pass it to syslogd to do the logging in a separate file.
jobs
Junior Poster in Training
58 posts since Jan 2007
Reputation Points: 10
Solved Threads: 0
Then you need to look up how syslogd works. Google for it.
WaltP
Posting Sage w/ dash of thyme
10,492 posts since May 2006
Reputation Points: 3,348
Solved Threads: 943