diff options
| author | Jeff Halter <868228+jhalter@users.noreply.github.com> | 2024-07-21 12:47:18 -0700 |
|---|---|---|
| committer | Jeff Halter <868228+jhalter@users.noreply.github.com> | 2024-07-21 12:47:18 -0700 |
| commit | adcd4879d93e6d298ff2644178bc47c1eb8d1da4 (patch) | |
| tree | 782399a609d8e09163c0e2f2fb3a3e916c75dd9c /internal | |
| parent | dcd23d5355badf66c34ffd63d3c44734e87ebf17 (diff) | |
Clean up logging
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/mobius/logger.go | 44 | ||||
| -rw-r--r-- | internal/mobius/transaction_handlers.go | 2 |
2 files changed, 44 insertions, 2 deletions
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") } |