Can I redirect logfiles to syslog?

8,495

Solution 1

Have you tried using logger with process substitution?

$ forever -a >(logger -t forever) -o >(logger -t app.js) -e >(logger -t app.js) app.js

You can play around with the logger -p switch for specifying log levels, warn, info, err, etc. as well as other logger switches. The forever -l needed to be changed to forever -a.

I tried this with a few of the sample files installed by forever and it worked. Each distro may log to different log file by default, you'll have to experiment with logger switches.

Solution 2

With rsyslog you can use the Text File Input Module to monitor log files and process them.

http://www.rsyslog.com/using-the-text-file-input-module/

Share:
8,495

Related videos on Youtube

Sander Marechal
Author by

Sander Marechal

Updated on September 18, 2022

Comments

  • Sander Marechal
    Sander Marechal almost 2 years

    I have a Node.js server that is being monitored by forever. Forever generates three logfiles: the server STDOUT, STDERR and the log of forever itself.

    $ forever -l forever.log -o out.log -e err.log app.js
    

    But instead of logging to logfiles I would like to log everything to syslog, optionally with adding a prefix of some sorts so my syslog processing servers can sort everything out.

    On StackOverflow, someone suggested that this can be handled using some bash wrapper and suggested I ask here. So, how would I get those logs into syslog instead of into files?

  • sr_
    sr_ over 12 years
  • Sander Marechal
    Sander Marechal over 12 years
    Thanks, that sounds perfect! I'll give it a try when I'm back at work on Monday.
  • bsd
    bsd over 12 years
    @SanderMarechal Experiment with logger by itself, figure out which switches will help you, then modify the example to suit. Good luck.
  • Mark Stosberg
    Mark Stosberg almost 9 years
    This is true, but log rotation is more involved this way because the application continues to hold the file descriptors open to log to them, possibly requiring the app to restarted when the logs are rotated. That's not an issue when logging directly to syslog via logger.
  • Ben
    Ben almost 9 years