// watchEvents logs and collect metrics of database events. func watchEvents(db *freegeoip.DB) { for { select { case file := <-db.NotifyOpen(): log.Println("database loaded:", file) dbEventCounter.WithLabelValues("loaded").Inc() case err := <-db.NotifyError(): log.Println("database error:", err) dbEventCounter.WithLabelValues("failed").Inc() case msg := <-db.NotifyInfo(): log.Println("database info:", msg) case <-db.NotifyClose(): return } } }
// logEvents logs database events. func logEvents(db *freegeoip.DB) { for { select { case file := <-db.NotifyOpen(): log.Println("database loaded:", file) case err := <-db.NotifyError(): log.Println("database error:", err) case <-db.NotifyClose(): return } } }