...

Source file src/github.com/Microsoft/go-winio/pkg/etwlogrus/opts.go

Documentation: github.com/Microsoft/go-winio/pkg/etwlogrus

     1  //go:build windows
     2  
     3  package etwlogrus
     4  
     5  import (
     6  	"github.com/sirupsen/logrus"
     7  
     8  	"github.com/Microsoft/go-winio/pkg/etw"
     9  )
    10  
    11  // etw provider
    12  
    13  // WithNewETWProvider registers a new ETW provider and sets the hook to log using it.
    14  // The provider will be closed when the hook is closed.
    15  func WithNewETWProvider(n string) HookOpt {
    16  	return func(h *Hook) error {
    17  		provider, err := etw.NewProvider(n, nil)
    18  		if err != nil {
    19  			return err
    20  		}
    21  
    22  		h.provider = provider
    23  		h.closeProvider = true
    24  		return nil
    25  	}
    26  }
    27  
    28  // WithExistingETWProvider configures the hook to use an existing ETW provider.
    29  // The provider will not be closed when the hook is closed.
    30  func WithExistingETWProvider(p *etw.Provider) HookOpt {
    31  	return func(h *Hook) error {
    32  		h.provider = p
    33  		h.closeProvider = false
    34  		return nil
    35  	}
    36  }
    37  
    38  // WithGetName sets the ETW EventName of an event to the value returned by f
    39  // If the name is empty, the default event name will be used.
    40  func WithGetName(f func(*logrus.Entry) string) HookOpt {
    41  	return func(h *Hook) error {
    42  		h.getName = f
    43  		return nil
    44  	}
    45  }
    46  
    47  // WithEventOpts allows additional ETW event properties (keywords, tags, etc.) to be specified.
    48  func WithEventOpts(f func(*logrus.Entry) []etw.EventOpt) HookOpt {
    49  	return func(h *Hook) error {
    50  		h.getEventsOpts = f
    51  		return nil
    52  	}
    53  }
    54  

View as plain text