{Josh Rendek}

<3 Ruby & Go

Getting Upstart to Log to Syslog With Tags

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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
respawn
respawn limit 15 5

start on runlevel [2345]
stop on runlevel [06]

setuid app-user
setgid app-user

script
  # Redirect stdout to syslog
  mkfifo /tmp/app-stdout-fifo
  ( logger -p user.info -t your-app-tag </tmp/app-stdout-fifo & )
  exec 1>/tmp/app-stdout-fifo
  rm /tmp/app-stdout-fifo

  # Redirect stderr to syslog
  mkfifo /tmp/app-stderr-fifo
  ( logger -p user.err  -t your-app-tag </tmp/app-stderr-fifo & )
  exec 2>/tmp/app-stderr-fifo
  rm /tmp/app-stderr-fifo

  exec ./your-app-binary
end script

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

Comments