943,815 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 3750
  • C RSS
Dec 16th, 2007
0

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

Expand Post »
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?
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
jobs is offline Offline
58 posts
since Jan 2007
Dec 16th, 2007
0

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.
Reputation Points: 11
Solved Threads: 7
Light Poster
yagiD is offline Offline
35 posts
since Dec 2007
Dec 17th, 2007
0

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?
Moderator
Reputation Points: 3278
Solved Threads: 892
Posting Sage
WaltP is offline Offline
7,718 posts
since May 2006
Dec 17th, 2007
0

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

Click to Expand / Collapse  Quote originally posted by WaltP ...
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
Reputation Points: 73
Solved Threads: 20
Posting Whiz in Training
ssharish2005 is offline Offline
253 posts
since Dec 2006
Dec 17th, 2007
0

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

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.
Moderator
Reputation Points: 3278
Solved Threads: 892
Posting Sage
WaltP is offline Offline
7,718 posts
since May 2006
Dec 17th, 2007
0

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

Click to Expand / Collapse  Quote originally posted by WaltP ...
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
Reputation Points: 73
Solved Threads: 20
Posting Whiz in Training
ssharish2005 is offline Offline
253 posts
since Dec 2006
Dec 17th, 2007
0

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

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
Reputation Points: 73
Solved Threads: 20
Posting Whiz in Training
ssharish2005 is offline Offline
253 posts
since Dec 2006
Dec 17th, 2007
0

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

Click to Expand / Collapse  Quote originally posted by WaltP ...
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.
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
jobs is offline Offline
58 posts
since Jan 2007
Dec 18th, 2007
0

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

Then you need to look up how syslogd works. Google for it.
Moderator
Reputation Points: 3278
Solved Threads: 892
Posting Sage
WaltP is offline Offline
7,718 posts
since May 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: Getting Current time and adding some time interval
Next Thread in C Forum Timeline: pic16f84a





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC