From b42568bf2223423fa0028255b26455b9f0560681 Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Mon, 13 Jan 2025 14:14:44 +0800 Subject: Update logging code --- main.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index f1c28ba..bf503f4 100644 --- a/main.go +++ b/main.go @@ -18,27 +18,31 @@ func main() { err := load_config(*config_path) if err != nil { - panic(err) + clog.Fatal(1, "Configuration file not found at "+*config_path) } listener, err := net.Listen(config.MX.Net, config.MX.Addr) if err != nil { - panic(err) + clog.Fatal(1, "MX: Cannot listen: "+err.Error()) } defer listener.Close() + clog.Info("MX: Listening via " + config.MX.Net + " on " + config.MX.Addr) for { conn, err := listener.Accept() if err != nil { - panic(err) + clog.Error("MX: Cannot accept connection: "+err.Error()) } + clog.Info("MX: Accepted connection from " + conn.RemoteAddr().String()) go func() { ctx, cancel := context.WithCancel(context.Background()) defer cancel() err := handle_mx_recv_conn(ctx, conn) if err != nil && !errors.Is(err, io.EOF) { - clog.Error("connection handler returned error", "err", err) + clog.Error("MX: Connection handler for " + conn.RemoteAddr().String() + " returned error: " + err.Error()) + } else { + clog.Error("MX: Connection handler for " + conn.RemoteAddr().String() + " returned error: " + err.Error()) } }() } -- cgit v1.2.3