Search code examples
linuxunixlogginggopanic

Is there any efficient way to get panic log of Go program under Unix easily?


Since I'm running a Go program as server, I need some mechanism to catch panic log if anything goes wrong for later analyze & debug. Is there any efficient way to get panic log of Go program under Unix easily? Can you guys introduce your experience about this? Thanks :)


Solution

  • I get a notification on my phone for some of my fatal panics on go programs. Here's how:

    First, I generally run everything under daemontools (or similar) so it's monitored and will restart itself on failure.

    Then, I generally log to syslog using the built-in log package. My syslog forwards to papertrail where I can review the state of things, set up alerts, etc... It is here I forward undesirable event notifications to an email address and notifymyandroid so I can be made aware of problems, search for similar recent issues, look at context around the problems, etc...

    ...but you can't log your own uncaught fatal panic, so I wrote logexec to execute the program and log its stdout and stderr separately along with an unsuccessful exit notification.

    Example:

    logexec -tag myprogram /path/to/myprogram -and -its arguments