-
C (
http://www.daniweb.com/forums/forum118.html)
| jobs | Dec 16th, 2007 3:13 pm | |
| 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? |
| yagiD | Dec 16th, 2007 8:20 pm | |
| Re: newbie: C-Program write to /var/log/mylog via syslog Look for C file operations and also how to get the system date. A little googling will do. |
| WaltP | Dec 17th, 2007 12:14 am | |
| Re: newbie: C-Program write to /var/log/mylog via syslog Do you really want your operating system to do the logging? Or do you only need a file created with log entries in it? |
| ssharish2005 | Dec 17th, 2007 3:56 am | |
| Re: newbie: C-Program write to /var/log/mylog via syslog Quote: Originally Posted by WaltP (Post 492559) 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 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
ssharish |
| WaltP | Dec 17th, 2007 4:13 am | |
| Re: newbie: C-Program write to /var/log/mylog via syslog Quote: Originally Posted by ssharish2005 (Post 492708) 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. |
| ssharish2005 | Dec 17th, 2007 4:17 am | |
| Re: newbie: C-Program write to /var/log/mylog via syslog Quote: Originally Posted by WaltP (Post 492720) 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. | Sorry i dint say that, perhaps u confused between the OP and me. I just question u. So there no feature in the OS which basically logs any events for the applications, instead we need to write ower own. Thats fine.
Thanks a lot
ssharish |
| ssharish2005 | Dec 17th, 2007 4:20 am | |
| Re: newbie: C-Program write to /var/log/mylog via syslog there u go a pesudocode for u
void writetofile(char *log)
{
open file
check file open status
build the log message with time and append the *log using sprintf
write log to file
close file
}
ssharish |
| jobs | Dec 17th, 2007 12:47 pm | |
| Re: newbie: C-Program write to /var/log/mylog via syslog Quote: Originally Posted by WaltP (Post 492559) 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. |
| WaltP | Dec 18th, 2007 1:21 am | |
| Re: newbie: C-Program write to /var/log/mylog via syslog Then you need to look up how syslogd works. Google for it. |
| All times are GMT -4. The time now is 8:42 pm. | |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC