newbie: C-Program write to /var/log/mylog via syslog

Reply

Join Date: Jan 2007
Posts: 58
Reputation: jobs is an unknown quantity at this point 
Solved Threads: 0
jobs jobs is offline Offline
Junior Poster in Training

newbie: C-Program write to /var/log/mylog via syslog

 
0
  #1
Dec 16th, 2007
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:MMS LOG_TYPE: MESSAGE

I need to have date and time in format yyyy/mm/dd 24HR:MMS. Log_type is an severity of error. and MESSAGE is acutal error message.

Any suggestions in doing this in C?
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 35
Reputation: yagiD is an unknown quantity at this point 
Solved Threads: 7
yagiD's Avatar
yagiD yagiD is offline Offline
Light Poster

Re: newbie: C-Program write to /var/log/mylog via syslog

 
0
  #2
Dec 16th, 2007
Look for C file operations and also how to get the system date. A little googling will do.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,114
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 281
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

Re: newbie: C-Program write to /var/log/mylog via syslog

 
0
  #3
Dec 17th, 2007
Do you really want your operating system to do the logging? Or do you only need a file created with log entries in it?
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 241
Reputation: ssharish2005 is on a distinguished road 
Solved Threads: 20
ssharish2005's Avatar
ssharish2005 ssharish2005 is offline Offline
Posting Whiz in Training

Re: newbie: C-Program write to /var/log/mylog via syslog

 
0
  #4
Dec 17th, 2007
Originally Posted by WaltP View Post
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
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,114
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 281
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

Re: newbie: C-Program write to /var/log/mylog via syslog

 
0
  #5
Dec 17th, 2007
Originally Posted by ssharish2005 View Post
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.
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 241
Reputation: ssharish2005 is on a distinguished road 
Solved Threads: 20
ssharish2005's Avatar
ssharish2005 ssharish2005 is offline Offline
Posting Whiz in Training

Re: newbie: C-Program write to /var/log/mylog via syslog

 
0
  #6
Dec 17th, 2007
Originally Posted by WaltP View Post
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
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 241
Reputation: ssharish2005 is on a distinguished road 
Solved Threads: 20
ssharish2005's Avatar
ssharish2005 ssharish2005 is offline Offline
Posting Whiz in Training

Re: newbie: C-Program write to /var/log/mylog via syslog

 
0
  #7
Dec 17th, 2007
there u go a pesudocode for u

  1. void writetofile(char *log)
  2. {
  3. open file
  4. check file open status
  5.  
  6. build the log message with time and append the *log using sprintf
  7.  
  8. write log to file
  9.  
  10. close file
  11. }

ssharish
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 58
Reputation: jobs is an unknown quantity at this point 
Solved Threads: 0
jobs jobs is offline Offline
Junior Poster in Training

Re: newbie: C-Program write to /var/log/mylog via syslog

 
0
  #8
Dec 17th, 2007
Originally Posted by WaltP View Post
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.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,114
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 281
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

Re: newbie: C-Program write to /var/log/mylog via syslog

 
0
  #9
Dec 18th, 2007
Then you need to look up how syslogd works. Google for it.
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC