good morning!!!!

Skip to content
Commits on Source (2)
......@@ -3,7 +3,6 @@ package fxplus
import (
"log/slog"
"os"
"strings"
"github.com/lmittmann/tint"
"go.uber.org/fx"
......@@ -18,178 +17,5 @@ func NewLogger() *slog.Logger {
}
var WithLogger = fx.WithLogger(func(logger *slog.Logger) fxevent.Logger {
return &eventLogger{L: logger}
return &fxevent.SlogLogger{Logger: logger}
})
type eventLogger struct {
L *slog.Logger
}
func (l *eventLogger) LogEvent(event fxevent.Event) {
switch e := event.(type) {
case *fxevent.OnStartExecuting:
l.L.Debug("[Fx] OnStart hook executing",
"callee", e.FunctionName,
"caller", e.CallerName,
)
case *fxevent.OnStartExecuted:
if e.Err != nil {
l.L.Error("[Fx] OnStart hook failed",
"callee", e.FunctionName,
"caller", e.CallerName,
"err", e.Err,
)
} else {
l.L.Debug("[Fx] OnStart hook executed",
"callee", e.FunctionName,
"caller", e.CallerName,
"runtime", e.Runtime.String(),
)
}
case *fxevent.OnStopExecuting:
l.L.Debug("[Fx] OnStop hook executing",
"callee", e.FunctionName,
"caller", e.CallerName,
)
case *fxevent.OnStopExecuted:
if e.Err != nil {
l.L.Error("[Fx] OnStop hook failed",
"callee", e.FunctionName,
"caller", e.CallerName,
"err", e.Err,
)
} else {
l.L.Debug("[Fx] OnStop hook executed",
"callee", e.FunctionName,
"caller", e.CallerName,
"runtime", e.Runtime.String(),
)
}
case *fxevent.Supplied:
if e.Err != nil {
l.L.Error("[Fx] error encountered while applying options",
"type", e.TypeName,
"stacktrace", e.StackTrace,
"moduletrace", e.ModuleTrace,
"module", e.ModuleName,
"err", e.Err,
)
} else {
l.L.Debug("[Fx] supplied",
"type", e.TypeName,
// "stacktrace", e.StackTrace,
// "moduletrace", e.ModuleTrace,
"module", e.ModuleName,
)
}
case *fxevent.Provided:
for _, rtype := range e.OutputTypeNames {
l.L.Debug("[Fx] provided",
"constructor", e.ConstructorName,
// "stacktrace", e.StackTrace,
// "moduletrace", e.ModuleTrace,
"module", e.ModuleName,
"type", rtype,
)
}
if e.Err != nil {
l.L.Error("[Fx] error encountered while applying options",
"module", e.ModuleName,
"stacktrace", e.StackTrace,
"moduletrace", e.ModuleTrace,
"err", e.Err,
)
}
case *fxevent.Replaced:
for _, rtype := range e.OutputTypeNames {
l.L.Debug("[Fx] replaced",
// "stacktrace", e.StackTrace,
"moduletrace", e.ModuleTrace,
"module", e.ModuleName,
"type", rtype,
)
}
if e.Err != nil {
l.L.Error("[Fx] error encountered while replacing",
"stacktrace", e.StackTrace,
"moduletrace", e.ModuleTrace,
"module", e.ModuleName,
"err", e.Err,
)
}
case *fxevent.Decorated:
for _, rtype := range e.OutputTypeNames {
l.L.Debug("[Fx] decorated",
"decorator", e.DecoratorName,
// "stacktrace", e.StackTrace,
"moduletrace", e.ModuleTrace,
"module", e.ModuleName,
"type", rtype,
)
}
if e.Err != nil {
l.L.Error("[Fx] error encountered while applying options",
"stacktrace", e.StackTrace,
"moduletrace", e.ModuleTrace,
"module", e.ModuleName,
"err", e.Err,
)
}
case *fxevent.Run:
if e.Err != nil {
l.L.Error("[Fx] error returned",
"name", e.Name,
"kind", e.Kind,
"module", e.ModuleName,
"err", e.Err,
)
} else {
l.L.Debug("[Fx] run",
"name", e.Name,
"kind", e.Kind,
"module", e.ModuleName,
)
}
case *fxevent.Invoking:
// Do not log stack as it will make logs hard to read.
l.L.Debug("[Fx] invoking",
"function", e.FunctionName,
"module", e.ModuleName,
)
case *fxevent.Invoked:
if e.Err != nil {
l.L.Error("[Fx] invoke failed",
"err", e.Err,
"stack", e.Trace,
"function", e.FunctionName,
"module", e.ModuleName,
)
}
case *fxevent.Stopping:
l.L.Debug("[Fx] received signal",
"signal", strings.ToUpper(e.Signal.String()),
)
case *fxevent.Stopped:
if e.Err != nil {
l.L.Error("[Fx] stop failed", "err", e.Err)
}
case *fxevent.RollingBack:
l.L.Error("[Fx] start failed, rolling back", "err", e.StartErr)
case *fxevent.RolledBack:
if e.Err != nil {
l.L.Error("[Fx] rollback failed", "err", e.Err)
}
case *fxevent.Started:
if e.Err != nil {
l.L.Error("[Fx] start failed", "err", e.Err)
} else {
l.L.Info("[Fx] app started")
}
case *fxevent.LoggerInitialized:
if e.Err != nil {
l.L.Error("[Fx] custom logger initialization failed", "err", e.Err)
} else {
l.L.Debug("[Fx] initialized custom fxevent.Logger", "function", e.ConstructorName)
}
}
}
......@@ -11,9 +11,9 @@ require (
github.com/go-chi/chi/v5 v5.0.12
github.com/joho/godotenv v1.5.1
github.com/lmittmann/tint v1.0.4
github.com/stretchr/testify v1.8.4
go.uber.org/fx v1.20.1
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225
github.com/stretchr/testify v1.9.0
go.uber.org/fx v1.21.0
golang.org/x/exp v0.0.0-20240318143956-a85f2c67cd81
golang.org/x/sync v0.6.0
sigs.k8s.io/yaml v1.4.0
)
......@@ -26,6 +26,6 @@ require (
go.uber.org/dig v1.17.1 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/sys v0.18.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
......@@ -22,12 +22,16 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE=
go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
go.uber.org/dig v1.17.1 h1:Tga8Lz8PcYNsWsyHMZ1Vm0OQOUaJNDyvPImgbAu9YSc=
go.uber.org/dig v1.17.1/go.mod h1:Us0rSJiThwCv2GteUN0Q7OKvU7n5J4dxZ9JKUXozFdE=
go.uber.org/fx v1.20.1 h1:zVwVQGS8zYvhh9Xxcu4w1M6ESyeMzebzj2NbSayZ4Mk=
go.uber.org/fx v1.20.1/go.mod h1:iSYNbHf2y55acNCwCXKx7LbWb5WG1Bnue5RDXz1OREg=
go.uber.org/fx v1.21.0 h1:qqD6k7PyFHONffW5speYx403ywanuASqU4Rqdpc22XY=
go.uber.org/fx v1.21.0/go.mod h1:HT2M7d7RHo+ebKGh9NRcrsrHHfpZ60nW3QRubMRfv48=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
......@@ -36,10 +40,14 @@ go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 h1:LfspQV/FYTatPTr/3HzIcmiUFH7PGP+OQ6mgDYo3yuQ=
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225/go.mod h1:CxmFvTBINI24O/j8iY7H1xHzx2i4OsyguNBmN/uPtqc=
golang.org/x/exp v0.0.0-20240318143956-a85f2c67cd81 h1:6R2FC06FonbXQ8pK11/PDFY6N6LWlf9KlzibaCapmqc=
golang.org/x/exp v0.0.0-20240318143956-a85f2c67cd81/go.mod h1:CQ1k9gNrJ50XIzaKCRR2hssIjF07kZFEiieALBM/ARQ=
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
......