| | |
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 |
Tag cloud for C
adobe ansi api array arrays asterisks binarysearch calculate centimeter char convert copyimagefile copypdffile cprogramme creafecopyofanytypeoffileinc createcopyoffile csyntax directory drawing dynamic fflush file fork forloop frequency getlasterror givemetehcodez graphics gtkgcurlcompiling hacking hardware highest homework i/o inches incrementoperators infiniteloop interest kernel km lazy linked linkedlist linux linuxsegmentationfault list lists locate logical_drives match matrix microsoft motherboard multi mysql number open opendocumentformat opensource owf pattern pdf performance pointer pointers posix problem probleminc program programming pyramidusingturboccodes radix recursion recv repetition research scanf scheduling scripting segmentationfault send sequential shape socketprograming spoonfeeding stack standard string strings structures student systemcall testautomation turboc unix user variable voidmain() wab windows.h






