Browse Source

made logging more generic

master
David Haukeness 5 years ago
parent
commit
26f8b2b2a6
  1. 16
      main.go

16
main.go

@ -32,25 +32,21 @@ type botConfig struct { @@ -32,25 +32,21 @@ type botConfig struct {
// Debug provides printing only when --debug flag is set or BOT_DEBUG env var is set
func (b *bot) debug(s string, a ...interface{}) {
if b.config.Debug {
log.Printf(s, a...)
if b.config.LogConvIDStr != "" {
b.logToChat(s, a...)
}
b.log(s, a...)
}
}
// logToChat will send this message to the keybase chat configured in b.logConv
func (b *bot) logToChat(s string, a ...interface{}) {
// if the ConvIdStr isn't blank try to log
// logToChat will send this message to the keybase chat configured in b.config.LogConvIDStr
func (b *bot) log(s string, a ...interface{}) {
// if the ConvIdStr isn't blank try to log to chat
if b.config.LogConvIDStr != "" {
// if you can't send the message, log the error to stdout
if _, err := b.k.SendMessageByConvID(chat1.ConvIDStr(b.config.LogConvIDStr), s, a...); err != nil {
log.Printf("Unable to log to keybase chat: %s", err)
}
} else {
// otherwise (and you shouldn't be here but....) log it to stdout
log.Println("Unable to log to keybase chat, logging ConvIDStr is not set")
}
// and then log it to stdout
log.Printf(s, a...)
}
// newBot returns a new empty bot

Loading…
Cancel
Save