1package etw
2
3// Channel represents the ETW logging channel that is used. It can be used by
4// event consumers to give an event special treatment.
5type Channel uint8
6
7const (
8	// ChannelTraceLogging is the default channel for TraceLogging events. It is
9	// not required to be used for TraceLogging, but will prevent decoding
10	// issues for these events on older operating systems.
11	ChannelTraceLogging Channel = 11
12)
13
14// Level represents the ETW logging level. There are several predefined levels
15// that are commonly used, but technically anything from 0-255 is allowed.
16// Lower levels indicate more important events, and 0 indicates an event that
17// will always be collected.
18type Level uint8
19
20// Predefined ETW log levels.
21const (
22	LevelAlways Level = iota
23	LevelCritical
24	LevelError
25	LevelWarning
26	LevelInfo
27	LevelVerbose
28)
29
30// EventDescriptor represents various metadata for an ETW event.
31type EventDescriptor struct {
32	id      uint16
33	version uint8
34	Channel Channel
35	Level   Level
36	Opcode  uint8
37	Task    uint16
38	Keyword uint64
39}
40
41// NewEventDescriptor returns an EventDescriptor initialized for use with
42// TraceLogging.
43func NewEventDescriptor() *EventDescriptor {
44	// Standard TraceLogging events default to the TraceLogging channel, and
45	// verbose level.
46	return &EventDescriptor{
47		Channel: ChannelTraceLogging,
48		Level:   LevelVerbose,
49	}
50}
51
52// Identity returns the identity of the event. If the identity is not 0, it
53// should uniquely identify the other event metadata (contained in
54// EventDescriptor, and field metadata). Only the lower 24 bits of this value
55// are relevant.
56func (ed *EventDescriptor) Identity() uint32 {
57	return (uint32(ed.version) << 16) | uint32(ed.id)
58}
59
60// SetIdentity sets the identity of the event. If the identity is not 0, it
61// should uniquely identify the other event metadata (contained in
62// EventDescriptor, and field metadata). Only the lower 24 bits of this value
63// are relevant.
64func (ed *EventDescriptor) SetIdentity(identity uint32) {
65	ed.id = uint16(identity)
66	ed.version = uint8(identity >> 16)
67}
68