From 1a3c40140a90ca60e2595545f05c1dbc8758bd44 Mon Sep 17 00:00:00 2001 From: eleksir Date: Wed, 8 Oct 2025 00:48:39 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D1=91=D0=BD=20?= =?UTF-8?q?=D1=84=D0=BE=D1=80=D0=BC=D0=B0=D1=82=20=D0=B4=D0=B0=D1=82=D1=8B?= =?UTF-8?q?=20=D0=BD=D0=B0=20=D0=B3=D0=BE=D1=88=D0=BD=D1=8B=D0=B9=20DateTi?= =?UTF-8?q?me?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/aleesa-misc-go/main.go | 92 +++++++++++++++++--------------------- 1 file changed, 41 insertions(+), 51 deletions(-) diff --git a/cmd/aleesa-misc-go/main.go b/cmd/aleesa-misc-go/main.go index 0d1e815..49f5020 100644 --- a/cmd/aleesa-misc-go/main.go +++ b/cmd/aleesa-misc-go/main.go @@ -14,7 +14,10 @@ import ( ) func main() { - var err error + var ( + err error + loglevel slog.Level + ) misc.ReadConfig() @@ -32,67 +35,52 @@ func main() { // no panic, no trace. switch misc.Config.Loglevel { case "error": - slog.SetDefault( - slog.New( - slog.NewTextHandler( - loghandler, - &slog.HandlerOptions{ - Level: slog.LevelError, - }, - ), - ), - ) + loglevel = slog.LevelError case "warn": - slog.SetDefault( - slog.New( - slog.NewTextHandler( - loghandler, - &slog.HandlerOptions{ - Level: slog.LevelWarn, - }, - ), - ), - ) + loglevel = slog.LevelWarn case "info": - slog.SetDefault( - slog.New( - slog.NewTextHandler( - loghandler, - &slog.HandlerOptions{ - Level: slog.LevelInfo, - }, - ), - ), - ) + loglevel = slog.LevelInfo case "debug": - slog.SetDefault( - slog.New( - slog.NewTextHandler( - loghandler, - &slog.HandlerOptions{ - Level: slog.LevelDebug, - }, - ), - ), - ) + loglevel = slog.LevelDebug default: - slog.SetDefault( - slog.New( - slog.NewTextHandler( - loghandler, - &slog.HandlerOptions{ - Level: slog.LevelInfo, - }, - ), - ), - ) + loglevel = slog.LevelInfo } + opts := &slog.HandlerOptions{ + // Use the ReplaceAttr function on the handler options + // to be able to replace any single attribute in the log output + ReplaceAttr: func(groups []string, a slog.Attr) slog.Attr { + // check that we are handling the time key + if a.Key != slog.TimeKey { + return a + } + + t := a.Value.Time() + + // change the value from a time.Time to a String + // where the string has the correct time format. + a.Value = slog.StringValue(t.Format(time.DateTime)) + + return a + }, + + Level: loglevel, + } + + slog.SetDefault( + slog.New( + slog.NewTextHandler( + loghandler, + opts, + ), + ), + ) + // Иницализируем клиента Редиски. misc.RedisClient = redis.NewClient(&redis.Options{ Addr: fmt.Sprintf("%s:%d", misc.Config.Server, misc.Config.Port), @@ -120,3 +108,5 @@ func main() { } } } + +/* vim: set ft=go noet ai ts=4 sw=4 sts=4: */