Add JSON structured logging
This commit is contained in:
parent
60b9d77873
commit
c06d77485c
6 changed files with 51 additions and 6 deletions
22
main.go
22
main.go
|
|
@ -27,25 +27,37 @@ func main() {
|
|||
log.Fatal(err)
|
||||
}
|
||||
|
||||
startBot()
|
||||
initLogger()
|
||||
|
||||
err = startBot()
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func startBot() {
|
||||
func startBot() error {
|
||||
session, _ := discordgo.New("Bot " + *Token)
|
||||
|
||||
err := session.Open()
|
||||
if err != nil {
|
||||
log.Fatalf("could not open session: %s", err)
|
||||
Log.Error("could not open discord session", "type", "error", "error", err)
|
||||
return err
|
||||
}
|
||||
|
||||
Log.Info("shutting down gracefully", "type", "shutdown")
|
||||
|
||||
sigch := make(chan os.Signal, 1)
|
||||
signal.Notify(sigch, os.Interrupt)
|
||||
<-sigch
|
||||
|
||||
log.Printf("shutting down gracefully...")
|
||||
Log.Info("shutting down gracefully", "type", "shutdown")
|
||||
|
||||
err = session.Close()
|
||||
if err != nil {
|
||||
log.Printf("could not close session gracefully: %s", err)
|
||||
Log.Error("could not close discord session gracefully", "type", "error", "error", err)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue