Documentation
¶
Overview ¶
Package logger defines the structured AppLogger interface and slog-backed helpers.
Index ¶
- type AppLogger
- type Field
- func WithAny(key string, val any) Field
- func WithBool(key string, v bool) Field
- func WithClusterID(clusterID string) Field
- func WithError(err error) Field
- func WithFilePath(filePath string) Field
- func WithFloat32(key string, v float32) Field
- func WithFloat64(key string, v float64) Field
- func WithFlow(val string) Field
- func WithGatewayID(gatewayID string) Field
- func WithInt(key string, v int) Field
- func WithInt32(key string, v int32) Field
- func WithInt64(key string, v int64) Field
- func WithModule(val string) Field
- func WithPeer(info peer.AddrInfo) Field
- func WithPeerAddrs(info peer.AddrInfo) Field
- func WithPeerID(info peer.ID) Field
- func WithRunID(val string) Field
- func WithService(serviceName string) Field
- func WithString(key, v string) Field
- func WithTopic(topic string) Field
- func WithTopicBytes(topic []byte) Field
- func WithUint(key string, v uint) Field
- func WithUint64(key string, v uint64) Field
- type LogMode
- type SLogger
- func (l *SLogger) Debug(message string, fields ...Field)
- func (l *SLogger) Error(message string, err error, fields ...Field)
- func (l *SLogger) Fatal(message string, err error, fields ...Field)
- func (l *SLogger) Info(message string, fields ...Field)
- func (l *SLogger) Slog() *slog.Logger
- func (l *SLogger) With(fields ...Field) AppLogger
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AppLogger ¶
type AppLogger interface {
Info(message string, fields ...Field)
Error(message string, err error, fields ...Field)
Debug(message string, fields ...Field)
Fatal(message string, err error, fields ...Field)
With(fields ...Field) AppLogger
Slog() *slog.Logger
}
AppLogger defines the structured logger interface.
func InitLogger ¶
InitLogger initializes a multi-output JSON logger with slog. At least one writer must be provided.
func NewAppSLogger ¶
NewAppSLogger creates a default AppLogger writing to STDERR.
type Field ¶
type Field struct {
// contains filtered or unexported fields
}
Field represents a typed key-value pair for structured logging.
func WithClusterID ¶
func WithError ¶
WithError creates a Field with key "err" containing the error message. Returns a pointer to the Field.
func WithFilePath ¶
WithFilePath creates a Field with key "file" and the given file path.
func WithFloat32 ¶
WithFloat32 creates a Field with a float32 value.
func WithFloat64 ¶
WithFloat64 creates a Field with a float64 value.
func WithGatewayID ¶
func WithModule ¶
WithModule creates a Field with key "module" and the given value. Returns a pointer to the Field.
func WithPeerAddrs ¶
WithPeerAddrs adds comma separated multiaddrs of the given peer
func WithService ¶
WithService creates a Field with key "service" and the given service name.
func WithString ¶
WithString creates a Field with a string value.
func WithTopicBytes ¶
WithTopicBytes adds a topic represented as byte slice
func WithUint ¶
WithUint creates a Field with a uint value. Uses Uint64 internally as slog has no Uint() function.
func WithUint64 ¶
WithUint64 creates a Field with a uint64 value.
type SLogger ¶
type SLogger struct {
// contains filtered or unexported fields
}
SLogger is an implementation of AppLogger backed by slog.
func NewAppLogger ¶
NewAppLogger creates a default AppLogger writing to STDERR.