package etwlogrus

import "github.com/Microsoft/go-winio/pkg/etwlogrus"

Index

Variables

var ErrNoProvider = errors.New("no ETW registered provider")

ErrNoProvider is returned when a hook is created without a provider being configured.

Types

type Hook

type Hook struct {
	// contains filtered or unexported fields
}

Hook is a Logrus hook which logs received events to ETW.

func NewHook

func NewHook(providerName string, opts ...HookOpt) (*Hook, error)

NewHook registers a new ETW provider and returns a hook to log from it. The provider will be closed when the hook is closed.

func NewHookFromOpts

func NewHookFromOpts(opts ...HookOpt) (*Hook, error)

NewHookFromOpts creates a new hook with the provided options. An error is returned if the hook does not have a valid provider.

func NewHookFromProvider

func NewHookFromProvider(provider *etw.Provider, opts ...HookOpt) (*Hook, error)

NewHookFromProvider creates a new hook based on an existing ETW provider. The provider will not be closed when the hook is closed.

func (*Hook) Close

func (h *Hook) Close() error

Close cleans up the hook and closes the ETW provider. If the provder was registered by etwlogrus, it will be closed as part of `Close`. If the provider was passed in, it will not be closed.

func (*Hook) Fire

func (h *Hook) Fire(e *logrus.Entry) error

Fire receives each Logrus entry as it is logged, and logs it to ETW.

func (*Hook) Levels

func (*Hook) Levels() []logrus.Level

Levels returns the set of levels that this hook wants to receive log entries for.

type HookOpt

type HookOpt func(*Hook) error

HookOpt is an option to change the behavior of the Logrus ETW hook.

func WithEventOpts

func WithEventOpts(f func(*logrus.Entry) []etw.EventOpt) HookOpt

WithEventOpts allows additional ETW event properties (keywords, tags, etc.) to be specified.

func WithExistingETWProvider

func WithExistingETWProvider(p *etw.Provider) HookOpt

WithExistingETWProvider configures the hook to use an existing ETW provider. The provider will not be closed when the hook is closed.

func WithGetName

func WithGetName(f func(*logrus.Entry) string) HookOpt

WithGetName sets the ETW EventName of an event to the value returned by f If the name is empty, the default event name will be used.

func WithNewETWProvider

func WithNewETWProvider(n string) HookOpt

WithNewETWProvider registers a new ETW provider and sets the hook to log using it. The provider will be closed when the hook is closed.

Source Files

hook.go opts.go

Version
v0.6.1
Published
Apr 14, 2023
Platform
windows/amd64
Imports
4 packages
Last checked
8 hours ago

Tools for package owners.