logger

package
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 11, 2025 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
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.

View Source
const (
	LevelTrace slog.Level = slog.LevelDebug - 4
)

Variables

This section is empty.

Functions

func Data

func Data(d any) slog.Attr

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

func Error(err error) slog.Attr

Error adds error to the log

if err:= f(); err != nil {
	log.Error("calling f", logger.Error(err))
}

func New

func New(cfg *LogConfiguration) (*slog.Logger, error)

func NodeID

func NodeID(id peer.ID) slog.Attr

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).

func Shard

func Shard(partition types.PartitionID, shard types.ShardID) slog.Attr

Shard creates shard id/partition id attribute.

Shard specific components (ie shard validator) should create logger which adds this attribute automatically, ie RootChain should use it when logging message specific to particular shard.

func UnitID

func UnitID(id []byte) slog.Attr

UnitID is used to log ID of the primary unit (bill, token, token type,...) associated to the logging call.

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);

func NewABHandler

func NewABHandler(h slog.Handler, goroutineID bool) *ABHandler

func (*ABHandler) Enabled

func (h *ABHandler) Enabled(ctx context.Context, level slog.Level) bool

func (*ABHandler) Handle

func (h *ABHandler) Handle(ctx context.Context, r slog.Record) error

func (*ABHandler) Handler

func (h *ABHandler) Handler() slog.Handler

func (*ABHandler) WithAttrs

func (h *ABHandler) WithAttrs(attrs []slog.Attr) slog.Handler

func (*ABHandler) WithGroup

func (h *ABHandler) WithGroup(name string) slog.Handler

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
}

func (*LogConfiguration) Handler

func (cfg *LogConfiguration) Handler(out io.Writer) (slog.Handler, error)

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) Enabled

func (h *RoundHandler) Enabled(ctx context.Context, level slog.Level) bool

func (*RoundHandler) Handle

func (h *RoundHandler) Handle(ctx context.Context, r slog.Record) error

func (*RoundHandler) Handler

func (h *RoundHandler) Handler() slog.Handler

func (*RoundHandler) WithAttrs

func (h *RoundHandler) WithAttrs(attrs []slog.Attr) slog.Handler

func (*RoundHandler) WithGroup

func (h *RoundHandler) WithGroup(name string) slog.Handler

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL