Improving logging

This commit is contained in:
Saxon Nelson-Milton 2023-02-08 17:15:30 +10:30
parent 683bb923cb
commit adc62a6442
2 changed files with 8 additions and 7 deletions

View File

@ -135,7 +135,6 @@ func (m *broadcastManager) recv(w http.ResponseWriter, r *http.Request) {
done := m.dogNotifier.handlerInvoked("recv") done := m.dogNotifier.handlerInvoked("recv")
defer done() defer done()
m.log.Debug("recv handler")
q := r.URL.Query() q := r.URL.Query()
ma := MAC(q.Get("ma")) ma := MAC(q.Get("ma"))
@ -304,16 +303,15 @@ func (m *broadcastManager) createOrUpdate(broadcast Broadcast) error {
} }
switch broadcast.status { switch broadcast.status {
case statusCreate: case statusActive, statusPlay, statusCreate:
fallthrough m.log.Info("updating configuration for mac","mac",broadcast.mac)
case statusActive, statusPlay:
signal, ok := m.slateExitSignals[broadcast.mac] signal, ok := m.slateExitSignals[broadcast.mac]
if ok { if ok {
close(signal) close(signal)
delete(m.slateExitSignals, broadcast.mac) delete(m.slateExitSignals, broadcast.mac)
} }
case statusSlate: case statusSlate:
m.log.Debug("slate request") m.log.Info("slate request")
// If there's a signal channel it means that we're already writing the slate // If there's a signal channel it means that we're already writing the slate
// image and theres nothing to do, so return. // image and theres nothing to do, so return.
_, ok := m.slateExitSignals[broadcast.mac] _, ok := m.slateExitSignals[broadcast.mac]
@ -382,5 +380,6 @@ func main() {
go m.dogNotifier.notify() go m.dogNotifier.notify()
log.Info("listening", "host", *host, "port", *port)
http.ListenAndServe(*host+":"+*port, nil) http.ListenAndServe(*host+":"+*port, nil)
} }

View File

@ -26,7 +26,6 @@ LICENSE
package main package main
import ( import (
"log"
"os" "os"
"os/signal" "os/signal"
"sync" "sync"
@ -132,6 +131,7 @@ func (n *watchdogNotifier) notify() {
// If this fails for any reason it indicates a systemd service configuration // If this fails for any reason it indicates a systemd service configuration
// issue, and therefore programmer error, so do fatal log to cause crash. // issue, and therefore programmer error, so do fatal log to cause crash.
n.log.Debug("notifying watchdog")
supported, err := daemon.SdNotify(false, daemon.SdNotifyWatchdog) supported, err := daemon.SdNotify(false, daemon.SdNotifyWatchdog)
if err != nil { if err != nil {
n.log.Fatal("error from systemd watchdog notify", "error", err) n.log.Fatal("error from systemd watchdog notify", "error", err)
@ -167,6 +167,7 @@ func (n *watchdogNotifier) handlersUnhealthy() bool {
func (n *watchdogNotifier) handlerInvoked(name string) func() { func (n *watchdogNotifier) handlerInvoked(name string) func() {
n.mu.Lock() n.mu.Lock()
defer n.mu.Unlock() defer n.mu.Unlock()
n.log.Info("handler invoked", "name", name)
id := n.curId id := n.curId
n.curId++ n.curId++
@ -175,9 +176,10 @@ func (n *watchdogNotifier) handlerInvoked(name string) func() {
return func() { return func() {
n.mu.Lock() n.mu.Lock()
defer n.mu.Unlock() defer n.mu.Unlock()
n.log.Info("handler done", "name", name)
if _, ok := n.activeHandlers[id]; !ok { if _, ok := n.activeHandlers[id]; !ok {
log.Fatal("handler id not in map", "name", name) n.log.Fatal("handler id not in map", "name", name)
} }
delete(n.activeHandlers, id) delete(n.activeHandlers, id)