| | |
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 |
* ansi api array arrays bash binarysearch calculate centimeter changingto char character convert copyanyfile copypdffile createcopyoffile createprocess() directory dynamic execv fflush file floatingpointvalidation fork forloop frequency function getlasterror getlogicaldrivestrin givemetehcodez grade graphics gtkgcurlcompiling gtkwinlinux hardware highest histogram homework i/o ide inches infiniteloop initialization input intmain() iso keyboard km license linked linkedlist linux list looping loopinsideloop. lowest matrix microsoft mysql oddnumber open opendocumentformat openwebfoundation pdf pointer pointers posix power program programming pyramidusingturboccodes read recursion recv recvblocked repetition reversing scanf scheduling segmentationfault send shape single socketprogramming stack standard strchr string suggestions test testautomation threads unix urboc user variable whythiscodecausesegmentationfault win32api windows.h windowsapi






