nmdc-log-service: prevent logging the same connection-state message repeatedly
This commit is contained in:
parent
86723f24ca
commit
8b23731451
20
main.go
20
main.go
@ -51,7 +51,11 @@ func LogMessage(hub, message string) {
|
||||
}
|
||||
}
|
||||
|
||||
func HubWorker(addr, nick, password string) {
|
||||
type HubWorker struct {
|
||||
LastConnectionStateMessage string
|
||||
}
|
||||
|
||||
func (this *HubWorker) MainLoop(addr, nick, password string) {
|
||||
|
||||
opts := libnmdc.HubConnectionOptions{
|
||||
Address: libnmdc.HubAddress(addr),
|
||||
@ -71,11 +75,16 @@ func HubWorker(addr, nick, password string) {
|
||||
switch event.EventType {
|
||||
case libnmdc.EVENT_CONNECTION_STATE_CHANGED:
|
||||
if LogConnectionState {
|
||||
str := "* " + event.StateChange.Format()
|
||||
if len(event.Message) > 0 {
|
||||
LogMessage(addr, "* "+event.StateChange.Format()+" ("+event.Message+")")
|
||||
} else {
|
||||
LogMessage(addr, "* "+event.StateChange.Format())
|
||||
str += " (" + event.Message + ")"
|
||||
}
|
||||
|
||||
// Prevent logging the same message repeatedly
|
||||
if str != this.LastConnectionStateMessage {
|
||||
LogMessage(addr, str)
|
||||
}
|
||||
this.LastConnectionStateMessage = str
|
||||
}
|
||||
|
||||
case libnmdc.EVENT_PUBLIC:
|
||||
@ -135,7 +144,8 @@ func main() {
|
||||
os.MkdirAll(GetDirectoryNameForHub(hubaddr), 0755)
|
||||
|
||||
// Launch logger
|
||||
go HubWorker(hubaddr, *nick, *password)
|
||||
hw := HubWorker{}
|
||||
go hw.MainLoop(hubaddr, *nick, *password)
|
||||
|
||||
launch_ct++
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user