Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 :)

like image 442
Reck Hou Avatar asked Dec 26 '22 04:12

Reck Hou


1 Answers

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
like image 120
Dustin Avatar answered Dec 28 '22 17:12

Dustin