Skip to content

Commit

Permalink
log messages improved
Browse files Browse the repository at this point in the history
  • Loading branch information
dmachard committed Feb 6, 2024
1 parent 9cc3e07 commit 0cf4247
Show file tree
Hide file tree
Showing 37 changed files with 81 additions and 86 deletions.
5 changes: 2 additions & 3 deletions collectors/dnsmessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,10 @@ func (c *DNSMessage) LogError(msg string, v ...interface{}) {
}

func (c *DNSMessage) Stop() {
// c.LogInfo("stopping routing handler...")
// c.RoutingHandler.Stop()
c.LogInfo("stopping collector...")

// read done channel and block until run is terminated
c.LogInfo("stopping run...")
c.LogInfo("stopping to run...")
c.stopRun <- true
<-c.doneRun

Expand Down
40 changes: 19 additions & 21 deletions collectors/dnstap.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bufio"
"crypto/tls"
"errors"
"fmt"
"io"
"net"
"os"
Expand Down Expand Up @@ -108,15 +107,15 @@ func (c *Dnstap) LogError(msg string, v ...interface{}) {
c.logger.Error(pkgutils.PrefixLogCollector+"["+c.name+" dnstap - "+msg, v...)
}

func (c *Dnstap) LogConnInfo(connID int, msg string, v ...interface{}) {
prefix := fmt.Sprintf(pkgutils.PrefixLogCollector+"[%s] dnstap#%d - ", c.name, connID)
c.logger.Info(prefix+msg, v...)
}
// func (c *Dnstap) LogConnInfo(connID int, msg string, v ...interface{}) {
// prefix := fmt.Sprintf(pkgutils.PrefixLogCollector+"[%s] dnstap#%d - ", c.name, connID)
// c.logger.Info(prefix+msg, v...)
// }

func (c *Dnstap) LogConnError(connID int, msg string, v ...interface{}) {
prefix := fmt.Sprintf(pkgutils.PrefixLogCollector+"[%s] dnstap#%d - ", c.name, connID)
c.logger.Error(prefix+msg, v...)
}
// func (c *Dnstap) LogConnError(connID int, msg string, v ...interface{}) {
// prefix := fmt.Sprintf(pkgutils.PrefixLogCollector+"[%s] dnstap#%d - ", c.name, connID)
// c.logger.Error(prefix+msg, v...)
// }

func (c *Dnstap) HandleConn(conn net.Conn) {
// close connection on function exit
Expand Down Expand Up @@ -154,9 +153,9 @@ func (c *Dnstap) HandleConn(conn net.Conn) {

// init framestream receiver
if err := fs.InitReceiver(); err != nil {
c.LogConnError(connID, "stream initialization: %s", err)
c.LogError("conn #%d - stream initialization: %s", connID, err)
} else {
c.LogConnInfo(connID, "receiver framestream initialized")
c.LogInfo("conn #%d - receiver framestream initialized", connID)
}

// process incoming frame and send it to dnstap consumer channel
Expand All @@ -178,9 +177,9 @@ func (c *Dnstap) HandleConn(conn net.Conn) {
}

if connClosed {
c.LogConnInfo(connID, "connection closed with peer %s", peer)
c.LogInfo("conn #%d - connection closed with peer %s", connID, peer)
} else {
c.LogConnError(connID, "framestream reader error: %s", err)
c.LogError("conn #%d - framestream reader error: %s", connID, err)
}

// the Stop function is already called, don't stop again
Expand All @@ -193,9 +192,9 @@ func (c *Dnstap) HandleConn(conn net.Conn) {
if frame.IsControl() {
if err := fs.ResetReceiver(frame); err != nil {
if errors.Is(err, io.EOF) {
c.LogConnInfo(connID, "framestream reseted by sender")
c.LogInfo("conn #%d - framestream reseted by sender", connID)
} else {
c.LogConnError(connID, "unexpected control framestream - %s", err)
c.LogError("conn #%d - unexpected control framestream: %s", connID, err)
}

}
Expand All @@ -212,7 +211,7 @@ func (c *Dnstap) HandleConn(conn net.Conn) {

// to avoid lock if the Stop function is already called
if c.stopCalled {
c.LogConnInfo(connID, "connection handler exited")
c.LogInfo("conn #%d - connection handler exited", connID)
return
}

Expand All @@ -234,7 +233,7 @@ func (c *Dnstap) HandleConn(conn net.Conn) {
}
c.Unlock()

c.LogConnInfo(connID, "connection handler terminated")
c.LogInfo("conn #%d - connection handler terminated", connID)
}

func (c *Dnstap) GetInputChannel() chan dnsutils.DNSMessage {
Expand All @@ -248,10 +247,10 @@ func (c *Dnstap) Stop() {
// to avoid some lock situations when the remose side closes
// the connection at the same time of this Stop function
c.stopCalled = true
c.LogInfo("stopping...")
c.LogInfo("stopping collector...")

// stop all powerdns processors
c.LogInfo("stopping processors...")
c.LogInfo("cleanup all active processors...")
for _, tapProc := range c.tapProcessors {
tapProc.Stop()
}
Expand Down Expand Up @@ -360,8 +359,7 @@ func (c *Dnstap) Run() {
c.LogInfo("starting collector...")
if c.listen == nil {
if err := c.Listen(); err != nil {
prefixlog := fmt.Sprintf("[%s] ", c.name)
c.logger.Fatal(prefixlog+"collector=dnstap listening failed: ", err)
c.logger.Fatal(pkgutils.PrefixLogCollector+"["+c.name+"] dnstap listening failed: ", err)
}
}

Expand Down
2 changes: 1 addition & 1 deletion collectors/dnstap_proxifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func (c *DnstapProxifier) GetInputChannel() chan dnsutils.DNSMessage {
}

func (c *DnstapProxifier) Stop() {
c.LogInfo("stopping...")
c.LogInfo("stopping collector...")
c.stopping = true

// closing properly current connections if exists
Expand Down
2 changes: 1 addition & 1 deletion collectors/file_ingestor.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (c *FileIngestor) GetInputChannel() chan dnsutils.DNSMessage {
}

func (c *FileIngestor) Stop() {
c.LogInfo("stopping...")
c.LogInfo("stopping collector...")

// exit to close properly
c.exit <- true
Expand Down
2 changes: 1 addition & 1 deletion collectors/file_tail.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (c *Tail) GetInputChannel() chan dnsutils.DNSMessage {
}

func (c *Tail) Stop() {
c.LogInfo("stopping...")
c.LogInfo("stopping collector...")

// Stop to follow file
c.LogInfo("stop following file...")
Expand Down
28 changes: 14 additions & 14 deletions collectors/powerdns.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,15 @@ func (c *ProtobufPowerDNS) LogError(msg string, v ...interface{}) {
c.logger.Error(pkgutils.PrefixLogCollector+"["+c.name+"] powerdns - "+msg, v...)
}

func (c *ProtobufPowerDNS) LogConnInfo(connID int, msg string, v ...interface{}) {
prefix := fmt.Sprintf(pkgutils.PrefixLogCollector+"[%s] powerdns#%d - ", c.name, connID)
c.logger.Info(prefix+msg, v...)
}
// func (c *ProtobufPowerDNS) LogConnInfo(connID int, msg string, v ...interface{}) {
// prefix := fmt.Sprintf(pkgutils.PrefixLogCollector+"[%s] powerdns#%d - ", c.name, connID)
// c.logger.Info(prefix+msg, v...)
// }

func (c *ProtobufPowerDNS) LogConnError(connID int, msg string, v ...interface{}) {
prefix := fmt.Sprintf(pkgutils.PrefixLogCollector+"[%s] powerdns#%d - ", c.name, connID)
c.logger.Error(prefix+msg, v...)
}
// func (c *ProtobufPowerDNS) LogConnError(connID int, msg string, v ...interface{}) {
// prefix := fmt.Sprintf(pkgutils.PrefixLogCollector+"[%s] powerdns#%d - ", c.name, connID)
// c.logger.Error(prefix+msg, v...)
// }

func (c *ProtobufPowerDNS) HandleConn(conn net.Conn) {
// close connection on function exit
Expand Down Expand Up @@ -151,9 +151,9 @@ func (c *ProtobufPowerDNS) HandleConn(conn net.Conn) {
}

if connClosed {
c.LogConnInfo(connID, "connection closed with peer %s", peer)
c.LogInfo("conn #%d - connection closed with peer %s", connID, peer)
} else {
c.LogConnError(connID, "powerdns reader error: %s", err)
c.LogError("conn #%d - powerdns reader error: %s", connID, err)
}

// stop processor
Expand All @@ -174,7 +174,7 @@ func (c *ProtobufPowerDNS) HandleConn(conn net.Conn) {

// to avoid lock if the Stop function is already called
if c.stopCalled {
c.LogConnInfo(connID, "connection handler exited")
c.LogInfo("conn #%d - connection handler exited", connID)
return
}

Expand All @@ -196,7 +196,7 @@ func (c *ProtobufPowerDNS) HandleConn(conn net.Conn) {
}
c.Unlock()

c.LogConnInfo(connID, "connection handler terminated")
c.LogInfo("conn #%d - connection handler terminated", connID)
}

func (c *ProtobufPowerDNS) GetInputChannel() chan dnsutils.DNSMessage {
Expand All @@ -210,10 +210,10 @@ func (c *ProtobufPowerDNS) Stop() {
// to avoid some lock situations when the remose side closes
// the connection at the same time of this Stop function
c.stopCalled = true
c.LogInfo("stopping...")
c.LogInfo("stopping collector...")

// stop all powerdns processors
c.LogInfo("stopping processors...")
c.LogInfo("cleanup all active processors...")
for _, pdnsProc := range c.pdnsProcessors {
pdnsProc.Stop()
}
Expand Down
2 changes: 1 addition & 1 deletion collectors/sniffer_afpacket.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func (c *AfpacketSniffer) GetInputChannel() chan dnsutils.DNSMessage {
}

func (c *AfpacketSniffer) Stop() {
c.LogInfo("stopping...")
c.LogInfo("stopping collector...")

// exit to close properly
c.exit <- true
Expand Down
2 changes: 1 addition & 1 deletion collectors/sniffer_afpacket_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (c *AfpacketSniffer) GetInputChannel() chan dnsutils.DNSMessage {
}

func (c *AfpacketSniffer) Stop() {
c.LogInfo("stopping...")
c.LogInfo("stopping collector...")

// exit to close properly
c.exit <- true
Expand Down
2 changes: 1 addition & 1 deletion collectors/sniffer_afpacket_freebsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (c *AfpacketSniffer) GetInputChannel() chan dnsutils.DNSMessage {
}

func (c *AfpacketSniffer) Stop() {
c.LogInfo("stopping...")
c.LogInfo("stopping collector...")

// exit to close properly
c.exit <- true
Expand Down
2 changes: 1 addition & 1 deletion collectors/sniffer_afpacket_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (c *AfpacketSniffer) GetInputChannel() chan dnsutils.DNSMessage {
}

func (c *AfpacketSniffer) Stop() {
c.LogInfo("stopping...")
c.LogInfo("stopping collector...")

// exit to close properly
c.exit <- true
Expand Down
2 changes: 1 addition & 1 deletion collectors/sniffer_xdp.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (c *XDPSniffer) GetInputChannel() chan dnsutils.DNSMessage {
}

func (c *XDPSniffer) Stop() {
c.LogInfo("stopping...")
c.LogInfo("stopping collector...")

// exit to close properly
c.exit <- true
Expand Down
2 changes: 1 addition & 1 deletion collectors/sniffer_xdp_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (c *XDPSniffer) GetInputChannel() chan dnsutils.DNSMessage {
}

func (c *XDPSniffer) Stop() {
c.LogInfo("stopping...")
c.LogInfo("stopping collector...")

// exit to close properly
c.exit <- true
Expand Down
2 changes: 1 addition & 1 deletion collectors/tzsp.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (c *TZSPSniffer) GetInputChannel() chan dnsutils.DNSMessage {
}

func (c *TZSPSniffer) Stop() {
c.LogInfo("stopping...")
c.LogInfo("stopping collector...")

// Finally close the listener to unblock accept
c.exit <- true
Expand Down
2 changes: 1 addition & 1 deletion collectors/tzsp_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (c *TZSPSniffer) GetInputChannel() chan dnsutils.DNSMessage {
}

func (c *TZSPSniffer) Stop() {
c.LogInfo("stopping...")
c.LogInfo("stopping collector...")

// exit to close properly
c.exit <- true
Expand Down
2 changes: 1 addition & 1 deletion collectors/tzsp_freebsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (c *TZSPSniffer) GetInputChannel() chan dnsutils.DNSMessage {
}

func (c *TZSPSniffer) Stop() {
c.LogInfo("stopping...")
c.LogInfo("stopping collector...")

// exit to close properly
c.exit <- true
Expand Down
2 changes: 1 addition & 1 deletion collectors/tzsp_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (c *TZSPSniffer) GetInputChannel() chan dnsutils.DNSMessage {
}

func (c *TZSPSniffer) Stop() {
c.LogInfo("stopping...")
c.LogInfo("stopping collector...")

// exit to close properly
c.exit <- true
Expand Down
2 changes: 1 addition & 1 deletion loggers/dnstapclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (ds *DnstapSender) GetInputChannel() chan dnsutils.DNSMessage {
}

func (ds *DnstapSender) Stop() {
ds.LogInfo("stopping routing handler...")
ds.LogInfo("stopping logger...")
ds.RoutingHandler.Stop()

ds.LogInfo("stopping to run...")
Expand Down
2 changes: 1 addition & 1 deletion loggers/elasticsearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (ec *ElasticSearchClient) LogError(msg string, v ...interface{}) {
}

func (ec *ElasticSearchClient) Stop() {
ec.LogInfo("stopping routing handler...")
ec.LogInfo("stopping logger...")
ec.RoutingHandler.Stop()

ec.LogInfo("stopping to run...")
Expand Down
2 changes: 1 addition & 1 deletion loggers/falco.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (fc *FalcoClient) LogError(msg string, v ...interface{}) {
}

func (fc *FalcoClient) Stop() {
fc.LogInfo("stopping routing handler...")
fc.LogInfo("stopping logger...")
fc.RoutingHandler.Stop()

fc.LogInfo("stopping to run...")
Expand Down
2 changes: 1 addition & 1 deletion loggers/fluentd.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (fc *FluentdClient) GetInputChannel() chan dnsutils.DNSMessage {
}

func (fc *FluentdClient) Stop() {
fc.LogInfo("stopping routing handler...")
fc.LogInfo("stopping logger...")
fc.RoutingHandler.Stop()

fc.LogInfo("stopping to run...")
Expand Down
2 changes: 1 addition & 1 deletion loggers/influxdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (ic *InfluxDBClient) GetInputChannel() chan dnsutils.DNSMessage {
}

func (ic *InfluxDBClient) Stop() {
ic.LogInfo("stopping routing handler...")
ic.LogInfo("stopping logger...")
ic.RoutingHandler.Stop()

ic.LogInfo("stopping to run...")
Expand Down
2 changes: 1 addition & 1 deletion loggers/kafkaproducer.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (k *KafkaProducer) GetInputChannel() chan dnsutils.DNSMessage {
}

func (k *KafkaProducer) Stop() {
k.LogInfo("stopping routing handler...")
k.LogInfo("stopping logger...")
k.RoutingHandler.Stop()

k.LogInfo("stopping to run...")
Expand Down
2 changes: 1 addition & 1 deletion loggers/logfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (lf *LogFile) LogError(msg string, v ...interface{}) {
}

func (lf *LogFile) Stop() {
lf.LogInfo("stopping routing handler...")
lf.LogInfo("stopping logger...")
lf.RoutingHandler.Stop()

lf.LogInfo("stopping to run...")
Expand Down
2 changes: 1 addition & 1 deletion loggers/lokiclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func (c *LokiClient) GetInputChannel() chan dnsutils.DNSMessage {
}

func (c *LokiClient) Stop() {
c.LogInfo("stopping routing handler...")
c.LogInfo("stopping logger...")
c.RoutingHandler.Stop()

c.LogInfo("stopping to run...")
Expand Down
2 changes: 1 addition & 1 deletion loggers/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -1129,7 +1129,7 @@ func (c *Prometheus) GetInputChannel() chan dnsutils.DNSMessage {
}

func (c *Prometheus) Stop() {
c.LogInfo("stopping routing handler...")
c.LogInfo("stopping logger...")
c.RoutingHandler.Stop()

c.LogInfo("stopping to run...")
Expand Down
2 changes: 1 addition & 1 deletion loggers/redispub.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (c *RedisPub) GetInputChannel() chan dnsutils.DNSMessage {
}

func (c *RedisPub) Stop() {
c.LogInfo("stopping routing handler...")
c.LogInfo("stopping logger...")
c.RoutingHandler.Stop()

c.LogInfo("stopping to run...")
Expand Down
Loading

0 comments on commit 0cf4247

Please sign in to comment.