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 (
|
import (
|
||||||
"log"
|
"log"
|
||||||
|
"log/slog"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/mattn/go-isatty"
|
"github.com/mattn/go-isatty"
|
||||||
@ -16,8 +17,11 @@ type CustomLogger struct {
|
|||||||
handlers []Handler
|
handlers []Handler
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var ourCustomLogger *slog.Logger
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
slog.SetDefaultLogger(NewCustomLogger())
|
ourCustomLogger = NewCustomLogger()
|
||||||
|
slog.SetDefault(ourCustomLogger)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCustomLogger() *CustomLogger {
|
func NewCustomLogger() *CustomLogger {
|
||||||
|
@ -90,13 +90,6 @@ func (r *RELPHandler) connectToRELPServer() (net.Conn, error) {
|
|||||||
}
|
}
|
||||||
return nil, err
|
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 {
|
if relpDebug {
|
||||||
log.Printf("Successfully connected to RELP server at %s", net.JoinHostPort(host, port))
|
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 {
|
func (r *RELPHandler) sendEventToRELPServer(event Event) error {
|
||||||
jsonData, err := json.Marshal(event)
|
jsonData, err := json.Marshal(event)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error marshaling event: %v", err)
|
return fmt.Errorf("error marshaling event: %v", err)
|
||||||
}
|
}
|
||||||
_, err = r.conn.Write(jsonData)
|
_, err = r.conn.Write(jsonData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user