Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
When a Beat exits due to panic the stack trace is written to stderr. For Beats running under service managers where the stdout/err are discarded this makes it problematic to debug (or even detect a panic). This commit modifies the beat runner to catch (aka `recover`) the panicking main goroutine, log it with logp, flush the logger, then exit. This ensures that the panic is present in the log output. Under normal circumstances (no error) the final log message from every Beat will be `<beatname> stopped.`. When there is a panic a l`evel=fatal` log line will be written that contains the panic message and a stack trace. For example: ``` { "level": "info", "timestamp": "2018-01-26T13:36:59.708-0500", "caller": "runtime/asm_amd64.s:510", "message": "auditbeat stopped." } { "level": "fatal", "timestamp": "2018-01-26T13:36:59.709-0500", "logger": "auditbeat", "caller": "instance/beat.go:134", "message": "Failed due to panic.", "panic": "Oh no, big problem!", "stack": "github.com/elastic/beats/libbeat/cmd/instance.Run.func1.1\n\t/Users/akroh/go/src/github.com/elastic/beats/libbeat/cmd/instance/beat.go:134\nruntime.call32\n\t/Users/akroh/.gvm/versions/go1.9.2.darwin.amd64/src/runtime/asm_amd64.s:509\nruntime.gopanic\n\t/Users/akroh/.gvm/versions/go1.9.2.darwin.amd64/src/runtime/panic.go:491\ngithub.com/elastic/beats/libbeat/cmd/instance.(*Beat).launch\n\t/Users/akroh/go/src/github.com/elastic/beats/libbeat/cmd/instance/beat.go:315\ngithub.com/elastic/beats/libbeat/cmd/instance.Run.func1\n\t/Users/akroh/go/src/github.com/elastic/beats/libbeat/cmd/instance/beat.go:142\ngithub.com/elastic/beats/libbeat/cmd/instance.Run\n\t/Users/akroh/go/src/github.com/elastic/beats/libbeat/cmd/instance/beat.go:143\ngithub.com/elastic/beats/libbeat/cmd.genRunCmd.func1\n\t/Users/akroh/go/src/github.com/elastic/beats/libbeat/cmd/run.go:19\ngithub.com/elastic/beats/vendor/github.com/spf13/cobra.(*Command).execute\n\t/Users/akroh/go/src/github.com/elastic/beats/vendor/github.com/spf13/cobra/command.go:704\ngithub.com/elastic/beats/vendor/github.com/spf13/cobra.(*Command).ExecuteC\n\t/Users/akroh/go/src/github.com/elastic/beats/vendor/github.com/spf13/cobra/command.go:785\ngithub.com/elastic/beats/vendor/github.com/spf13/cobra.(*Command).Execute\n\t/Users/akroh/go/src/github.com/elastic/beats/vendor/github.com/spf13/cobra/command.go:738\nmain.main\n\t/Users/akroh/go/src/github.com/elastic/beats/auditbeat/main.go:14\nruntime.main\n\t/Users/akroh/.gvm/versions/go1.9.2.darwin.amd64/src/runtime/proc.go:195" } ``` Log that panic object seperately
- Loading branch information