Thread: Redirect C-program log message using syslog

  1. #1
    Registered User
    Join Date
    Jan 2008

    Redirect C-program log message using syslog

    I want to redirect all my C-Program messages (error, informational etc.) to my own file using syslog (Linux). I am sure many would have tried and this related mostly with syslog configuration. I could forward the messages to default syslog message file "/var/log/messages" , but I want how to configure to my own file. Am I need to do anything in the C-program itself to achieve this? or the configuration has to be done just in /etc/syslog.conf alone.

  2. #2
    Registered User
    Join Date
    Sep 2007
    I'm not sure I completely follow you.

    If you want to use the syslog() function to log errors, then you must configure your syslogd to log to files other than the default. C can't control how syslogd handles messages. Unless, I suppose, your syslogd has a way to easily control it at runtime. Mine doesn't.

    If you want to write to a file, why not just do it directly with C?

  3. #3
    Registered User
    Join Date
    Apr 2007
    If you are wanting to create your own log files for a program, you can redirect stdout and stderr to the files you wish after you create them.

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    For example:
    $ ./program >output.log 2>errors.log
    If you want to, you could open a log file from within your program and write messages to it. That way the messages would always go to the file and never to the screen.

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell

    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ:

    My website:
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Windows service event log message file
    By George2 in forum C# Programming
    Replies: 0
    Last Post: 05-22-2008, 03:24 AM
  2. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  3. error message program works ..
    By mad_muppet in forum C Programming
    Replies: 7
    Last Post: 09-21-2006, 02:30 PM
  4. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM
  5. Sorry, forgot to log in when I posted this message....
    By face_master in forum C++ Programming
    Replies: 2
    Last Post: 08-27-2001, 09:13 AM