aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorRunxi Yu <me@runxiyu.org>2024-12-12 08:05:46 +0800
committerRunxi Yu <me@runxiyu.org>2024-12-12 08:05:46 +0800
commit3b7e9385f3004fa70ce4ee5b3e8e6abdb7bd2f10 (patch)
treea9c6a02223b1e4f18390e075ea9fd0351953b4c0 /main.go
parentUse CID instead of connection pointers while logging (diff)
downloadmeseircd-3b7e9385f3004fa70ce4ee5b3e8e6abdb7bd2f10.tar.gz
meseircd-3b7e9385f3004fa70ce4ee5b3e8e6abdb7bd2f10.tar.zst
meseircd-3b7e9385f3004fa70ce4ee5b3e8e6abdb7bd2f10.zip
Use meselog instead of slog
Diffstat (limited to '')
-rw-r--r--main.go25
1 files changed, 11 insertions, 14 deletions
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
}
}