7

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?

13

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.

  • Thanks, that sounds perfect! I'll give it a try when I'm back at work on Monday. – Sander Marechal Mar 3 '12 at 17:45
  • @SanderMarechal Experiment with logger by itself, figure out which switches will help you, then modify the example to suit. Good luck. – bsd Mar 3 '12 at 17:53
  • 1
    This might have worked in the past, but now the -a option does not allow for an argument; i.e. the command must be `forever -a -o >(logger -t app.js) -e >(logger -t app.js) app.js' – radiospiel Oct 17 '14 at 14:21
4

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/

  • 2
    Btw, syslog-ng apparently can do this, too. – sr_ Mar 2 '12 at 15:11
  • 1
    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. – Mark Stosberg Jun 29 '15 at 13:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.