Documentation
¶
Overview ¶
Package fastlog configures structured slog handlers.
Environment defaults emit JSON events to stderr. The package registers stdout and stderr stream handlers by default:
import "github.com/InsideGallery/core/fastlog"
New code should prefer NewLoggerWithRegistry, SetupDefaultLogger, and InstallDefaultLogger so handler registries and process-wide defaults have explicit ownership.
Compatibility: NewLogger and SetupDefaultLog remain available for existing package-level wiring. File logging is available only when consumers import fastlog/handlers/logfile for legacy compatibility.
Index ¶
- Constants
- func NewLogger(cfg *Config, m ...slogmulti.Middleware) (*slog.Logger, error)deprecated
- func NewLoggerWithRegistry(cfg *Config, registry *handlers.Registry, m ...slogmulti.Middleware) (*slog.Logger, error)
- func SetupDefault(ctx context.Context, cfg *Config, m ...slogmulti.Middleware) (func() error, error)
- func SetupDefaultLog(m ...slogmulti.Middleware)deprecated
- type Config
- type DefaultLoggerHandle
Constants ¶
const EnvPrefix = "LOG"
const (
Separator = ":"
)
Variables ¶
This section is empty.
Functions ¶
func NewLogger
deprecated
added in
v1.1.0
func NewLoggerWithRegistry ¶ added in v1.1.0
func NewLoggerWithRegistry( cfg *Config, registry *handlers.Registry, m ...slogmulti.Middleware, ) (*slog.Logger, error)
NewLoggerWithRegistry creates a logger from explicit config and handler registry.
func SetupDefault ¶ added in v1.1.0
func SetupDefault( ctx context.Context, cfg *Config, m ...slogmulti.Middleware, ) (func() error, error)
SetupDefault creates and installs a process-wide logger from explicit config.
func SetupDefaultLog
deprecated
func SetupDefaultLog(m ...slogmulti.Middleware)
SetupDefaultLog reads logger config from environment and installs it as slog default.
Deprecated: use GetConfigFromEnv plus SetupDefault so callers can handle errors and close the logger.
Types ¶
type Config ¶
type Config struct {
Outputs []string `env:"_OUTPUTS" envDefault:"stderr:json"`
Level slog.Level `env:"_LEVEL" envDefault:"INFO"`
Caller bool `env:"_CALLER" envDefault:"true"`
ErrorFormatting bool `env:"_ERROR_FORMATING" envDefault:"false"`
}
func GetConfigFromEnv ¶
func (*Config) GetHandler
deprecated
func (*Config) GetHandlerFromRegistry ¶ added in v1.1.0
func (c *Config) GetHandlerFromRegistry(registry *handlers.Registry, m ...slogmulti.Middleware) (slog.Handler, error)
GetHandlerFromRegistry returns a slog handler from an explicit handler registry.
type DefaultLoggerHandle ¶ added in v1.1.0
type DefaultLoggerHandle struct {
// contains filtered or unexported fields
}
DefaultLoggerHandle restores a previous slog default logger.
func InstallDefaultLogger ¶ added in v1.1.0
func InstallDefaultLogger(logger *slog.Logger) *DefaultLoggerHandle
InstallDefaultLogger installs a process-wide slog default with a restore path.
Use InstallDefaultLogger when callers need bespoke logger wiring. SetupDefault is the standard bootstrap.
func SetupDefaultLogger ¶ added in v1.1.0
func SetupDefaultLogger(cfg *Config, m ...slogmulti.Middleware) (*DefaultLoggerHandle, error)
SetupDefaultLogger creates and installs a process-wide logger from explicit config.
func (*DefaultLoggerHandle) Close ¶ added in v1.1.0
func (h *DefaultLoggerHandle) Close() error
Close restores the previous process-wide slog default and flushes the installed handler.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package all imports every in-tree fastlog handler so each handler registers with the default fastlog handler registry through its init hook.
|
Package all imports every in-tree fastlog handler so each handler registers with the default fastlog handler registry through its init hook. |
|
logfile
Package logfile provides a legacy opt-in slog writer that appends log events to a local file.
|
Package logfile provides a legacy opt-in slog writer that appends log events to a local file. |