X-Git-Url: https://git.realraum.at/?p=svn42.git;a=blobdiff_plain;f=go%2Fr3-netstatus%2Fmain.go;h=b65e96e8c01f9b04c379134afbf654e384a7949d;hp=a2917a579921ad850224cdb9fc357793f1e1502f;hb=b7182b7f1d5dae86d81310beaa6ce6d693696572;hpb=0d2bd96d2c019a7c0e0282898809fb03962ca701 diff --git a/go/r3-netstatus/main.go b/go/r3-netstatus/main.go index a2917a5..b65e96e 100644 --- a/go/r3-netstatus/main.go +++ b/go/r3-netstatus/main.go @@ -27,6 +27,7 @@ var ( r3eventssub_port_ string button_press_timeout_ int64 = 3600 brain_connect_addr_ string + enable_syslog_, enable_debug_ bool ) //------- @@ -38,7 +39,11 @@ func init() { flag.StringVar(&xmpp_state_save_dir_,"xstatedir","/flash/var/lib/r3netstatus/", "Directory to save XMPP bot state in") flag.StringVar(&r3eventssub_port_, "eventsubport", "tcp://wuzzler.realraum.at:4244", "zmq address to subscribe r3events") flag.StringVar(&brain_connect_addr_, "brainconnect", "tcp://wuzzler.realraum.at:4245", "address to ask about most recent stored events") + flag.BoolVar(&enable_syslog_, "syslog", false, "enable logging to syslog") + flag.BoolVar(&enable_debug_, "debug", false, "enable debug logging") flag.Parse() + if enable_syslog_ { LogEnableSyslog(); r3xmppbot.LogEnableSyslog() } + if enable_debug_ { LogEnableDebuglog(); r3xmppbot.LogEnableDebuglog() } } //------- @@ -61,7 +66,7 @@ func EventToXMPP(ps *pubsub.PubSub, xmpp_presence_events_chan_ chan <- interface defer func() { if x := recover(); x != nil { - fmt.Printf("handleIncomingXMPPStanzas: run time panic: %v", x) + Debug_.Printf("handleIncomingXMPPStanzas: run time panic: %v", x) ps.Unsub(events, "presence","door","buttons","updateinterval") close(xmpp_presence_events_chan_) } @@ -78,7 +83,7 @@ func EventToXMPP(ps *pubsub.PubSub, xmpp_presence_events_chan_ chan <- interface xmpp_presence_events_chan_ <- r3xmppbot.XMPPStatusEvent{r3xmppbot.ShowNotAvailabe, "Nobody is here"} for eventinterface := range(events) { - fmt.Println("event2xmpp", eventinterface) + Debug_.Println("event2xmpp", eventinterface) switch event := eventinterface.(type) { case r3events.PresenceUpdate: present = event.Present @@ -138,12 +143,12 @@ func main() { } else { fmt.Println(xmpperr) fmt.Println("XMPP Bot disabled") + Syslog_.Printf("XMPP Bot disabled due to error: %s", xmpperr) } // --- get update on most recent events --- answ := ZmqsAskQuestionsAndClose(zmqctx, brain_connect_addr_, [][][]byte{[][]byte{[]byte("DoorLockUpdate")}, [][]byte{[]byte("DoorAjarUpdate")}, [][]byte{[]byte("DoorCommandEvent")}, [][]byte{[]byte("PresenceUpdate")}, [][]byte{[]byte("IlluminationSensorUpdate")}, [][]byte{[]byte("TempSensorUpdate")}}) for _, a := range(answ) { - //~ fmt.Println("recent event:", a) ParseZMQr3Event(a, ps) }