better logging

This commit is contained in:
Holger Cremer
2018-01-04 22:40:37 +01:00
parent 5725bae3f9
commit 76b5ff15fd
3 changed files with 21 additions and 13 deletions

View File

@@ -5,11 +5,11 @@ After=network.target
[Service]
Type=simple
User=<Insert User>
Group=<Insert User>
User=status
Group=status
Environment="GIN_MODE=release"
WorkingDirectory=<Change>
ExecStart=<Change>/spaceDevices
WorkingDirectory=/home/status/spaceDevices2
ExecStart=/home/status/spaceDevices2/spaceDevices
Restart=always
RestartSec=60

View File

@@ -11,6 +11,7 @@ import (
"fmt"
"bytes"
"sort"
"strings"
)
var ignoredVisibility = [...]db.Visibility{db.VisibilityCriticalInfrastructure, db.VisibilityImportantInfrastructure,
@@ -54,17 +55,21 @@ func (d *DeviceData) newData(data []byte) {
if ok {
d.wifiSessionList = sessionsList
if ddLogger.Logger.Level >= logrus.DebugLevel {
people := make(map[string]interface{})
for _, p := range peopleAndDevices.People {
people[p.Name] = nil
}
peopleList := make([]string, len(people))
for k, _ := range people {
peopleList = append(peopleList, k)
peopleList := make([]string, 0, len(peopleAndDevices.People))
for _, person := range peopleAndDevices.People {
if len(person.Name) == 0 {
continue
}
personStr := person.Name + " ["
for _, device := range person.Devices {
personStr += device.Name + ","
}
personStr += "]"
peopleList = append(peopleList, personStr)
}
sort.Strings(peopleList)
ddLogger.Debugf("PeopleCount: %d, DeviceCount: %d, UnknownDevicesCount: %d, Persons: %s",
peopleAndDevices.PeopleCount, peopleAndDevices.DeviceCount, peopleAndDevices.UnknownDevicesCount, peopleList)
peopleAndDevices.PeopleCount, peopleAndDevices.DeviceCount, peopleAndDevices.UnknownDevicesCount, strings.Join(peopleList, "; "))
}
h := md5.New()
s := fmt.Sprintf("%v", peopleAndDevices)

View File

@@ -95,10 +95,13 @@ func (h *MqttHandler) SendPeopleAndDevices(data PeopleAndDevices) {
return
}
mqttLogger.Infof("Sending PeopleAndDevices: %d, %d, %d, %d",
data.PeopleCount, data.DeviceCount, data.UnknownDevicesCount, len(data.People))
token := h.client.Publish(TOPIC_DEVICES, 0, true, string(bytes))
ok := token.WaitTimeout(time.Duration(time.Second * 10))
if !ok {
mqttLogger.Infoln("Error sending devices to:", TOPIC_DEVICES)
mqttLogger.Warn("Error sending devices to:", TOPIC_DEVICES)
return
}
}