| | |
newbie: C-Program write to /var/log/mylog via syslog
![]() |
•
•
Join Date: Jan 2007
Posts: 58
Reputation:
Solved Threads: 0
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
S LOG_TYPE: MESSAGE
I need to have date and time in format yyyy/mm/dd 24HR:MM
S. Log_type is an severity of error. and MESSAGE is acutal error message.
Any suggestions in doing this in C?
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
S LOG_TYPE: MESSAGEI need to have date and time in format yyyy/mm/dd 24HR:MM
S. Log_type is an severity of error. and MESSAGE is acutal error message.Any suggestions in doing this in C?
•
•
•
•
Do you really want your operating system to do the logging? Or do you only need a file created with log entries in it?
ssharish
•
•
•
•
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
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
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
•
•
•
•
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 usessprintf()to put the message together. Open the file, write the message, close the file.
Thanks a lot
ssharish
there u go a pesudocode for u
ssharish
C Syntax (Toggle Plain Text)
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
![]() |
Other Threads in the C Forum
- Previous Thread: Getting Current time and adding some time interval
- Next Thread: pic16f84a
| Thread Tools | Search this Thread |
#include adobe ansi api array asterisks binarysearch changingto char character cm copyimagefile cprogramme creafecopyofanytypeoffileinc createcopyoffile csyntax database directory dynamic execv feet fgets file fork forloop frequency function getlasterror givemetehcodez global grade graphics gtkgcurlcompiling hacking hardware highest histogram i/o include incrementoperators infiniteloop input interest kernel keyboard kilometer license linked linkedlist linux linuxsegmentationfault list locate logical_drives looping loopinsideloop. lowest match matrix meter microsoft motherboard mqqueue mysql number odf opensource owf pattern pdf performance pointer posix probleminc process program programming radix recursion recv repetition research reversing scanf segmentationfault sequential shape socket socketprograming standard string systemcall threads turboc unix user voidmain() wab windows.h windowsapi






