| | |
newbie: C-Program write to /var/log/mylog via syslog
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
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 * append array arrays asterisks bash binarysearch calculate changingto char character cm copyimagefile creafecopyofanytypeoffileinc createprocess() database dynamic execv feet fgets file floatingpointvalidation fork forloop framework function getlogicaldrivestrin givemetehcodez global grade gtkwinlinux hacking histogram ide include incrementoperators input intmain() iso kernel keyboard kilometer km license linked linkedlist linux list lists locate logical_drives looping loopinsideloop. lowest matrix meter microsoft mqqueue number oddnumber odf opensource openwebfoundation overwrite owf pdf performance pointer posix probleminc process program programming radix recursion recv recvblocked research reversing scripting segmentationfault sequential single socket socketprogramming standard strchr string systemcall testing threads turboc unix urboc user variable wab whythiscodecausesegmentationfault windowsapi






