{ Josh Rendek }

<3 Go & Kubernetes

I was setting up the ELK stack and had quite a fun time trying to get upstart to log to syslog WITH a log tag ( aka: my-application ) so it could be filtered inside Kibana.

Here is a working example for STDOUT and STDERR:

 1respawn
 2respawn limit 15 5
 3
 4start on runlevel [2345]
 5stop on runlevel [06]
 6
 7setuid app-user
 8setgid app-user
 9
10script
11  # Redirect stdout to syslog
12  mkfifo /tmp/app-stdout-fifo
13  ( logger -p user.info -t your-app-tag </tmp/app-stdout-fifo & )
14  exec 1>/tmp/app-stdout-fifo
15  rm /tmp/app-stdout-fifo
16
17  # Redirect stderr to syslog
18  mkfifo /tmp/app-stderr-fifo
19  ( logger -p user.err  -t your-app-tag </tmp/app-stderr-fifo & )
20  exec 2>/tmp/app-stderr-fifo
21  rm /tmp/app-stderr-fifo
22
23  exec ./your-app-binary
24end script

Hope this helps someone else, there as a lot of mis-leading and broken examples on Google & StackOverflow.

comments powered by Disqus