Изменён формат даты на гошный DateTime
This commit is contained in:
@@ -14,7 +14,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var err error
|
var (
|
||||||
|
err error
|
||||||
|
loglevel slog.Level
|
||||||
|
)
|
||||||
|
|
||||||
misc.ReadConfig()
|
misc.ReadConfig()
|
||||||
|
|
||||||
@@ -32,67 +35,52 @@ func main() {
|
|||||||
// no panic, no trace.
|
// no panic, no trace.
|
||||||
switch misc.Config.Loglevel {
|
switch misc.Config.Loglevel {
|
||||||
case "error":
|
case "error":
|
||||||
slog.SetDefault(
|
loglevel = slog.LevelError
|
||||||
slog.New(
|
|
||||||
slog.NewTextHandler(
|
|
||||||
loghandler,
|
|
||||||
&slog.HandlerOptions{
|
|
||||||
Level: slog.LevelError,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
case "warn":
|
case "warn":
|
||||||
slog.SetDefault(
|
loglevel = slog.LevelWarn
|
||||||
slog.New(
|
|
||||||
slog.NewTextHandler(
|
|
||||||
loghandler,
|
|
||||||
&slog.HandlerOptions{
|
|
||||||
Level: slog.LevelWarn,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
case "info":
|
case "info":
|
||||||
slog.SetDefault(
|
loglevel = slog.LevelInfo
|
||||||
slog.New(
|
|
||||||
slog.NewTextHandler(
|
|
||||||
loghandler,
|
|
||||||
&slog.HandlerOptions{
|
|
||||||
Level: slog.LevelInfo,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
case "debug":
|
case "debug":
|
||||||
slog.SetDefault(
|
loglevel = slog.LevelDebug
|
||||||
slog.New(
|
|
||||||
slog.NewTextHandler(
|
|
||||||
loghandler,
|
|
||||||
&slog.HandlerOptions{
|
|
||||||
Level: slog.LevelDebug,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
slog.SetDefault(
|
loglevel = slog.LevelInfo
|
||||||
slog.New(
|
|
||||||
slog.NewTextHandler(
|
|
||||||
loghandler,
|
|
||||||
&slog.HandlerOptions{
|
|
||||||
Level: 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{
|
misc.RedisClient = redis.NewClient(&redis.Options{
|
||||||
Addr: fmt.Sprintf("%s:%d", misc.Config.Server, misc.Config.Port),
|
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: */
|
||||||
|
|||||||
Reference in New Issue
Block a user