aboutsummaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
Diffstat (limited to 'internal')
-rw-r--r--internal/mobius/api.go2
-rw-r--r--internal/mobius/logger.go19
-rw-r--r--internal/mobius/transaction_handlers.go12
3 files changed, 20 insertions, 13 deletions
diff --git a/internal/mobius/api.go b/internal/mobius/api.go
index adc9072..a574bf8 100644
--- a/internal/mobius/api.go
+++ b/internal/mobius/api.go
@@ -85,7 +85,7 @@ func NewAPIServer(hlServer *hotline.Server, reloadFunc func(), logger *slog.Logg
if err := hlServer.Redis.Del(context.Background(), hotline.RedisKeyOnline).Err(); err != nil {
srv.logger.Warn("Failed to clear online users in Redis", "err", err)
} else {
- srv.logger.Info("Cleared online users in Redis on startup")
+ srv.logger.Debug("Cleared online users in Redis on startup")
}
}
diff --git a/internal/mobius/logger.go b/internal/mobius/logger.go
index 60d4f0d..2f67a71 100644
--- a/internal/mobius/logger.go
+++ b/internal/mobius/logger.go
@@ -22,14 +22,21 @@ var logLevels = map[string]slog.Level{
}
func NewLogger(logLevel, logFile *string) *slog.Logger {
+ // Always log to stdout. Only add the rotating file writer when a log file path
+ // is configured; an empty Filename makes lumberjack write to a temp file.
+ var out io.Writer = os.Stdout
+ if *logFile != "" {
+ out = io.MultiWriter(os.Stdout, &lumberjack.Logger{
+ Filename: *logFile,
+ MaxSize: logMaxSize,
+ MaxBackups: logMaxBackups,
+ MaxAge: logMaxAge,
+ })
+ }
+
return slog.New(
slog.NewTextHandler(
- io.MultiWriter(os.Stdout, &lumberjack.Logger{
- Filename: *logFile,
- MaxSize: logMaxSize,
- MaxBackups: logMaxBackups,
- MaxAge: logMaxAge,
- }),
+ out,
&slog.HandlerOptions{
Level: logLevels[*logLevel],
ReplaceAttr: func(groups []string, a slog.Attr) slog.Attr {
diff --git a/internal/mobius/transaction_handlers.go b/internal/mobius/transaction_handlers.go
index b629be8..96b4f69 100644
--- a/internal/mobius/transaction_handlers.go
+++ b/internal/mobius/transaction_handlers.go
@@ -685,7 +685,7 @@ func HandleSetUser(cc *hotline.ClientConn, t *hotline.Transaction) (res []hotlin
err := cc.Server.AccountManager.Update(*account, account.Login)
if err != nil {
- cc.Logger.Error("Error updating account", "Err", err)
+ cc.Logger.Error("Error updating account", "err", err)
return cc.NewErrReply(t, ErrMsgUpdateAccount)
}
@@ -760,7 +760,7 @@ func HandleListUsers(cc *hotline.ClientConn, t *hotline.Transaction) (res []hotl
for _, acc := range cc.Server.AccountManager.List() {
b, err := io.ReadAll(&acc)
if err != nil {
- cc.Logger.Error("Error reading account", "Account", acc.Login, "Err", err)
+ cc.Logger.Error("Error reading account", "account", acc.Login, "err", err)
continue
}
@@ -831,7 +831,7 @@ func HandleUpdateUser(cc *hotline.ClientConn, t *hotline.Transaction) (res []hot
cc.Logger.Info("DeleteUser", "login", login)
if err := cc.Server.AccountManager.Delete(login); err != nil {
- cc.Logger.Error("Error deleting account", "Err", err)
+ cc.Logger.Error("Error deleting account", "err", err)
return cc.NewErrReply(t, ErrMsgDeleteAccount)
}
@@ -1005,7 +1005,7 @@ func HandleDeleteUser(cc *hotline.ClientConn, t *hotline.Transaction) (res []hot
login := t.GetField(hotline.FieldUserLogin).DecodeObfuscatedString()
if err := cc.Server.AccountManager.Delete(login); err != nil {
- cc.Logger.Error("Error deleting account", "Err", err)
+ cc.Logger.Error("Error deleting account", "err", err)
return cc.NewErrReply(t, ErrMsgDeleteAccount)
}
@@ -1269,7 +1269,7 @@ func HandleDisconnectUser(cc *hotline.ClientConn, t *hotline.Transaction) (res [
switch options[1] {
case 1:
// send message: "You are temporarily banned on this server"
- cc.Logger.Info("Disconnect & temporarily ban " + string(clientConn.UserName))
+ cc.Logger.Info("Disconnect & temporarily ban user", "username", string(clientConn.UserName))
res = append(res, hotline.NewTransaction(
hotline.TranServerMsg,
@@ -1288,7 +1288,7 @@ func HandleDisconnectUser(cc *hotline.ClientConn, t *hotline.Transaction) (res [
}
case 2:
// send message: "You are permanently banned on this server"
- cc.Logger.Info("Disconnect & ban " + string(clientConn.UserName))
+ cc.Logger.Info("Disconnect & ban user", "username", string(clientConn.UserName))
res = append(res, hotline.NewTransaction(
hotline.TranServerMsg,