From 3b7e9385f3004fa70ce4ee5b3e8e6abdb7bd2f10 Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Thu, 12 Dec 2024 08:05:46 +0800 Subject: Use meselog instead of slog --- main.go | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index ecfb4c5..e38974e 100644 --- a/main.go +++ b/main.go @@ -3,17 +3,14 @@ package main import ( "bufio" "log" - "log/slog" "net" - "os" + + "git.sr.ht/~runxiyu/meseircd/meselog" ) const VERSION = "MeseIRCd-0.0.0" func main() { - logger := slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: slog.LevelDebug})) - slog.SetDefault(logger) - setupCapls() self = &Server{ @@ -38,13 +35,13 @@ func main() { defer func() { raised := recover() if raised != nil { - slog.Error("connection routine panicked", "raised", raised) + meselog.Error("connection routine panicked", "raised", raised) } }() defer conn.Close() client, err := NewLocalClient(&conn) if err != nil { - slog.Error("cannot make new local client", "error", err) + meselog.Error("cannot make new local client", "error", err) } defer client.Teardown() client.handleConnection() @@ -58,11 +55,11 @@ messageLoop: for { line, err := reader.ReadString('\n') if err != nil { - slog.Error("error while reading from connection", "error", err) + meselog.Error("error while reading from connection", "error", err) (*client.conn).Close() return } - slog.Debug("recv", "line", line, "client", client.CID) + meselog.Debug("recv", "line", line, "client", client.CID) msg, err := parseIRCMsg(line) if err != nil { switch err { @@ -71,7 +68,7 @@ messageLoop: case ErrIllegalByte: err := client.Send(MakeMsg(self, "ERROR", err.Error())) if err != nil { - slog.Error("error while reporting illegal byte", "error", err, "client", client) + meselog.Error("error while reporting illegal byte", "error", err, "client", client) return } return @@ -80,14 +77,14 @@ messageLoop: case ErrBodyTooLong: err := client.Send(MakeMsg(self, ERR_INPUTTOOLONG, err.Error())) if err != nil { - slog.Error("error while reporting body too long", "error", err, "client", client) + meselog.Error("error while reporting body too long", "error", err, "client", client) return } continue messageLoop default: err := client.Send(MakeMsg(self, "ERROR", err.Error())) if err != nil { - slog.Error("error while reporting parser error", "error", err, "client", client) + meselog.Error("error while reporting parser error", "error", err, "client", client) } return } @@ -97,7 +94,7 @@ messageLoop: if !ok { err := client.Send(MakeMsg(self, ERR_UNKNOWNCOMMAND, msg.Command, "Unknown command")) if err != nil { - slog.Error("error while reporting unknown command", "error", err, "client", client) + meselog.Error("error while reporting unknown command", "error", err, "client", client) return } continue @@ -105,7 +102,7 @@ messageLoop: err = handler(msg, client) if err != nil { - slog.Error("handler error", "error", err, "client", client) + meselog.Error("handler error", "error", err, "client", client) return } } -- cgit v1.2.3