Show yggdrasilctl log buffer on panic

This commit is contained in:
Neil Alexander 2018-12-10 11:29:42 +00:00
parent b4b3609678
commit c78e1b98cc
No known key found for this signature in database
GPG Key ID: A02A2019A2BB0944

View File

@ -26,6 +26,13 @@ type admin_info map[string]interface{}
func main() { func main() {
logbuffer := &bytes.Buffer{} logbuffer := &bytes.Buffer{}
logger := log.New(logbuffer, "", log.Flags()) logger := log.New(logbuffer, "", log.Flags())
defer func() {
if r := recover(); r != nil {
logger.Println("Fatal error:", r)
fmt.Print(logbuffer)
os.Exit(1)
}
}()
endpoint := defaults.GetDefaults().DefaultAdminListen endpoint := defaults.GetDefaults().DefaultAdminListen
@ -102,7 +109,6 @@ func main() {
conn, err = net.Dial("tcp", endpoint) conn, err = net.Dial("tcp", endpoint)
} }
if err != nil { if err != nil {
fmt.Print(logbuffer)
panic(err) panic(err)
} }
logger.Println("Connected") logger.Println("Connected")
@ -137,7 +143,6 @@ func main() {
} }
if err := encoder.Encode(&send); err != nil { if err := encoder.Encode(&send); err != nil {
fmt.Print(logbuffer)
panic(err) panic(err)
} }
logger.Printf("Request sent") logger.Printf("Request sent")