From f8bd3147a4fafe97a8ad5ec8b48dbafb7e83a1f0 Mon Sep 17 00:00:00 2001 From: sneak Date: Tue, 14 May 2024 04:46:27 -0700 Subject: [PATCH] Refactored logging to use custom logger and set default logger. --- custom_logger.go | 6 +++++- relp_handler.go | 9 +-------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/custom_logger.go b/custom_logger.go index 6b57b99..f380616 100644 --- a/custom_logger.go +++ b/custom_logger.go @@ -2,6 +2,7 @@ package simplelog import ( "log" + "log/slog" "os" "github.com/mattn/go-isatty" @@ -16,8 +17,11 @@ type CustomLogger struct { handlers []Handler } +var ourCustomLogger *slog.Logger + func init() { - slog.SetDefaultLogger(NewCustomLogger()) + ourCustomLogger = NewCustomLogger() + slog.SetDefault(ourCustomLogger) } func NewCustomLogger() *CustomLogger { diff --git a/relp_handler.go b/relp_handler.go index 1ed3623..183686f 100644 --- a/relp_handler.go +++ b/relp_handler.go @@ -90,13 +90,6 @@ func (r *RELPHandler) connectToRELPServer() (net.Conn, error) { } return nil, err } - conn, err = net.Dial("tcp", net.JoinHostPort(host, port)) - if err != nil { - if relpDebug { - log.Printf("Failed to connect to RELP server at %s: %v", net.JoinHostPort(host, port), err) - } - return nil, err - } if relpDebug { log.Printf("Successfully connected to RELP server at %s", net.JoinHostPort(host, port)) } @@ -166,7 +159,7 @@ func (r *RELPHandler) processFailedEvents() { func (r *RELPHandler) sendEventToRELPServer(event Event) error { jsonData, err := json.Marshal(event) if err != nil { - return fmt.Errorf("error marshaling event: %v", err) + return fmt.Errorf("error marshaling event: %v", err) } _, err = r.conn.Write(jsonData) if err != nil {