File: opts.go

package info (click to toggle)
golang-github-microsoft-go-winio 0.6.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 764 kB
  • sloc: makefile: 3
file content (53 lines) | stat: -rw-r--r-- 1,286 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//go:build windows

package etwlogrus

import (
	"github.com/sirupsen/logrus"

	"github.com/Microsoft/go-winio/pkg/etw"
)

// etw provider

// WithNewETWProvider registers a new ETW provider and sets the hook to log using it.
// The provider will be closed when the hook is closed.
func WithNewETWProvider(n string) HookOpt {
	return func(h *Hook) error {
		provider, err := etw.NewProvider(n, nil)
		if err != nil {
			return err
		}

		h.provider = provider
		h.closeProvider = true
		return nil
	}
}

// WithExistingETWProvider configures the hook to use an existing ETW provider.
// The provider will not be closed when the hook is closed.
func WithExistingETWProvider(p *etw.Provider) HookOpt {
	return func(h *Hook) error {
		h.provider = p
		h.closeProvider = false
		return nil
	}
}

// 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 WithGetName(f func(*logrus.Entry) string) HookOpt {
	return func(h *Hook) error {
		h.getName = f
		return nil
	}
}

// WithEventOpts allows additional ETW event properties (keywords, tags, etc.) to be specified.
func WithEventOpts(f func(*logrus.Entry) []etw.EventOpt) HookOpt {
	return func(h *Hook) error {
		h.getEventsOpts = f
		return nil
	}
}