customizable subsystem loggers
This commit is contained in:
14
subsystem.go
14
subsystem.go
@@ -1,8 +1,14 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
)
|
||||
|
||||
// Subsystem represents a sub-system of the application, with its setup and
|
||||
// teardown functions and dependencies.
|
||||
type Subsystem struct {
|
||||
logger *slog.Logger
|
||||
name string
|
||||
setup setupFn
|
||||
teardown teardownFn
|
||||
@@ -28,3 +34,11 @@ func NewSubsystem(name string, opts SubsystemOpts) *Subsystem {
|
||||
depends: opts.Depends,
|
||||
}
|
||||
}
|
||||
|
||||
// Logger returns the logger for the subsystem.
|
||||
func (s *Subsystem) Logger() *slog.Logger {
|
||||
if s.logger == nil {
|
||||
panic(fmt.Sprintf("subsytem %s used before logger was initialized", s.name))
|
||||
}
|
||||
return s.logger
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user