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] [Service]
Type=simple Type=simple
User=<Insert User> User=status
Group=<Insert User> Group=status
Environment="GIN_MODE=release" Environment="GIN_MODE=release"
WorkingDirectory=<Change> WorkingDirectory=/home/status/spaceDevices2
ExecStart=<Change>/spaceDevices ExecStart=/home/status/spaceDevices2/spaceDevices
Restart=always Restart=always
RestartSec=60 RestartSec=60

View File

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

View File

@@ -95,10 +95,13 @@ func (h *MqttHandler) SendPeopleAndDevices(data PeopleAndDevices) {
return 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)) token := h.client.Publish(TOPIC_DEVICES, 0, true, string(bytes))
ok := token.WaitTimeout(time.Duration(time.Second * 10)) ok := token.WaitTimeout(time.Duration(time.Second * 10))
if !ok { if !ok {
mqttLogger.Infoln("Error sending devices to:", TOPIC_DEVICES) mqttLogger.Warn("Error sending devices to:", TOPIC_DEVICES)
return return
} }
} }