logger

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2024 License: AGPL-3.0 Imports: 18 Imported by: 8

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 "AB 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 Round

func Round(round uint64) slog.Attr

Round records current round number.

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

	ConsoleFormat *bool `yaml:"consoleFormat"` // -> Format
	ShowNodeID    *bool `yaml:"showNodeID"`    // -> PeerIDFormat
}

func (*LogConfiguration) Handler

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

Jump to

Keyboard shortcuts

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