Refactored logging to use custom logger and set default logger.
This commit is contained in:
parent
24c6ebe407
commit
f8bd3147a4
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue