aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd/mobius-hotline-server/main.go29
-rw-r--r--hotline/file_transfer.go3
-rw-r--r--hotline/server.go2
-rw-r--r--internal/mobius/logger.go44
-rw-r--r--internal/mobius/transaction_handlers.go2
5 files changed, 48 insertions, 32 deletions
diff --git a/cmd/mobius-hotline-server/main.go b/cmd/mobius-hotline-server/main.go
index 33ba7c2..6b82764 100644
--- a/cmd/mobius-hotline-server/main.go
+++ b/cmd/mobius-hotline-server/main.go
@@ -7,10 +7,8 @@ import (
"fmt"
"github.com/jhalter/mobius/hotline"
"github.com/jhalter/mobius/internal/mobius"
- "gopkg.in/natefinch/lumberjack.v2"
"io"
"log"
- "log/slog"
"os"
"os/signal"
"path"
@@ -21,12 +19,6 @@ import (
//go:embed mobius/config
var cfgTemplate embed.FS
-var logLevels = map[string]slog.Level{
- "debug": slog.LevelDebug,
- "info": slog.LevelInfo,
- "error": slog.LevelError,
-}
-
// Values swapped in by go-releaser at build time
var (
version = "dev"
@@ -52,21 +44,11 @@ func main() {
flag.Parse()
if *printVersion {
- fmt.Printf("mobius-hotline-server %s, commit %s, built at %s", version, commit, date)
+ fmt.Printf("mobius-hotline-server %s, commit %s, built on %s\n", version, commit, date)
os.Exit(0)
}
- slogger := slog.New(
- slog.NewTextHandler(
- io.MultiWriter(os.Stdout, &lumberjack.Logger{
- Filename: *logFile,
- MaxSize: 100, // MB
- MaxBackups: 3,
- MaxAge: 365, // days
- }),
- &slog.HandlerOptions{Level: logLevels[*logLevel]},
- ),
- )
+ slogger := mobius.NewLogger(logLevel, logFile)
// It's important for Windows compatibility to use path.Join and not filepath.Join for the config dir initialization.
// https://github.com/golang/go/issues/44305
@@ -181,12 +163,7 @@ func main() {
}
}()
- slogger.Info("Hotline server started",
- "version", version,
- "config", *configDir,
- "API port", fmt.Sprintf("%s:%v", *netInterface, *basePort),
- "Transfer port", fmt.Sprintf("%s:%v", *netInterface, *basePort+1),
- )
+ slogger.Info("Hotline server started", "version", version, "config", *configDir)
// Assign functions to handle specific Hotline transaction types
mobius.RegisterHandlers(srv)
diff --git a/hotline/file_transfer.go b/hotline/file_transfer.go
index 12725db..847c7fe 100644
--- a/hotline/file_transfer.go
+++ b/hotline/file_transfer.go
@@ -421,7 +421,6 @@ func DownloadFolderHandler(rwc io.ReadWriter, fullPath string, fileTransfer *Fil
}
subPath := path[basePathLen+1:]
- rLogger.Debug("Sending fileheader", "i", i, "path", path, "fullFilePath", fullPath, "subPath", subPath, "IsDir", info.IsDir())
if i == 1 {
return nil
@@ -437,8 +436,6 @@ func DownloadFolderHandler(rwc io.ReadWriter, fullPath string, fileTransfer *Fil
return err
}
- rLogger.Debug("Client folder download action", "action", fmt.Sprintf("%X", nextAction[0:2]))
-
var dataOffset int64
switch nextAction[1] {
diff --git a/hotline/server.go b/hotline/server.go
index c4d8f7f..5531bd3 100644
--- a/hotline/server.go
+++ b/hotline/server.go
@@ -400,7 +400,7 @@ func (s *Server) handleNewConnection(ctx context.Context, rwc io.ReadWriteCloser
return err
}
- c.Logger.Info("Login failed", "clientVersion", fmt.Sprintf("%x", c.Version))
+ c.Logger.Info("Incorrect login")
return nil
}
diff --git a/internal/mobius/logger.go b/internal/mobius/logger.go
new file mode 100644
index 0000000..909e6ab
--- /dev/null
+++ b/internal/mobius/logger.go
@@ -0,0 +1,44 @@
+package mobius
+
+import (
+ "gopkg.in/natefinch/lumberjack.v2"
+ "io"
+ "log/slog"
+ "os"
+ "time"
+)
+
+const (
+ logMaxSize = 100 // MB
+ logMaxBackups = 3
+ logMaxAge = 365 // days
+)
+
+var logLevels = map[string]slog.Level{
+ "debug": slog.LevelDebug,
+ "info": slog.LevelInfo,
+ "error": slog.LevelError,
+}
+
+func NewLogger(logLevel, logFile *string) *slog.Logger {
+ return slog.New(
+ slog.NewTextHandler(
+ io.MultiWriter(os.Stdout, &lumberjack.Logger{
+ Filename: *logFile,
+ MaxSize: logMaxSize,
+ MaxBackups: logMaxBackups,
+ MaxAge: logMaxAge,
+ }),
+ &slog.HandlerOptions{
+ Level: logLevels[*logLevel],
+ ReplaceAttr: func(groups []string, a slog.Attr) slog.Attr {
+ if a.Key == slog.TimeKey {
+ // Remove the milliseconds from the time field to save a few columns.
+ a.Value = slog.StringValue(a.Value.Time().Format(time.RFC3339))
+ }
+ return a
+ },
+ },
+ ),
+ )
+}
diff --git a/internal/mobius/transaction_handlers.go b/internal/mobius/transaction_handlers.go
index 759ee66..3253ff2 100644
--- a/internal/mobius/transaction_handlers.go
+++ b/internal/mobius/transaction_handlers.go
@@ -1772,8 +1772,6 @@ func HandleMakeAlias(cc *hotline.ClientConn, t *hotline.Transaction) (res []hotl
return res
}
- cc.Logger.Debug("Make alias", "src", fullFilePath, "dst", fullNewFilePath)
-
if err := cc.Server.FS.Symlink(fullFilePath, fullNewFilePath); err != nil {
return cc.NewErrReply(t, "Error creating alias")
}