Documentation
¶
Index ¶
- Constants
- func Data(d any) slog.Attr
- func Error(err error) slog.Attr
- func New(cfg *LogConfiguration) (*slog.Logger, error)
- func NodeID(id peer.ID) slog.Attr
- func Shard(partition types.PartitionID, shard types.ShardID) slog.Attr
- func UnitID(id []byte) slog.Attr
- type ABHandler
- func (h *ABHandler) Enabled(ctx context.Context, level slog.Level) bool
- func (h *ABHandler) Handle(ctx context.Context, r slog.Record) error
- func (h *ABHandler) Handler() slog.Handler
- func (h *ABHandler) WithAttrs(attrs []slog.Attr) slog.Handler
- func (h *ABHandler) WithGroup(name string) slog.Handler
- type LogConfiguration
- type RoundHandler
- func (h *RoundHandler) Enabled(ctx context.Context, level slog.Level) bool
- func (h *RoundHandler) Handle(ctx context.Context, r slog.Record) error
- func (h *RoundHandler) Handler() slog.Handler
- func (h *RoundHandler) WithAttrs(attrs []slog.Attr) slog.Handler
- func (h *RoundHandler) WithGroup(name string) slog.Handler
Constants ¶
const ( NodeIDKey = "node_id" ModuleKey = "module" GoIDKey = "go_id" ErrorKey = "err" RoundKey = "round" UnitIDKey = "unit_id" DataKey = "data" )
Log attribute key values. Generally shouldn't be used directly, use appropriate "attribute constructor function" instead.
Only define names here if they are common for multiple modules, module specific names should be defined in the module.
const (
LevelTrace slog.Level = slog.LevelDebug - 4
)
Variables ¶
This section is empty.
Functions ¶
func Data ¶
Data adds additional data field to the message.
slog.GroupValue shouldn't be used as the data - in the ECS formatter all groups will end up under the same key possibly causing problems with index!
Use of anonymous types is discouraged too.
func Error ¶
Error adds error to the log
if err:= f(); err != nil {
log.Error("calling f", logger.Error(err))
}
func NodeID ¶
NodeID adds "UBFT node ID" field.
This function should be used with logger.With() method to create sub-logger for the node (rather than adding NodeID call to individual logging calls).
Types ¶
type ABHandler ¶
type ABHandler struct {
// contains filtered or unexported fields
}
ABHandler is a slog handler which does some AB specific processing to the log:
- adds goroutine id field to the log record (if flag is set);
- adds trace/span id attributes (if present in the context);
type LogConfiguration ¶
type LogConfiguration struct {
Level string `yaml:"defaultLevel"`
Format string `yaml:"format"`
OutputPath string `yaml:"outputPath"`
TimeFormat string `yaml:"timeFormat"`
PeerIDFormat string `yaml:"peerIdFormat"`
ShowGoroutineID *bool `yaml:"showGoroutineID"`
// when Format==console this func will be used to determine
// whether to use color codes in log output
ConsoleSupportsColor func(io.Writer) bool
}
type RoundHandler ¶
type RoundHandler struct {
// contains filtered or unexported fields
}
func NewRoundHandler ¶
func NewRoundHandler(h slog.Handler, getRound func() uint64) *RoundHandler
NewRoundHandler creates slog handler which adds "round" attribute to each log record by calling the provided callback. Meant to be used with components which do have concept of current round, ie shard validator or RootChain node.
func (*RoundHandler) Handler ¶
func (h *RoundHandler) Handler() slog.Handler