mirror of
https://github.com/rwinkhart/go-winio.git
synced 2026-09-05 16:47:31 -04:00
[etw] Add String() functions, JSON field option (#285)
Add `String()` functions to `etw.Level` and `etw.Opcode` types. Add `etw.JSONStringField()`, which denotes a string field containing JSON data. Fix doc comment casing. Signed-off-by: Hamza El-Saawy <hamzaelsaawy@microsoft.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
//go:build windows
|
||||
|
||||
package etw
|
||||
|
||||
import "fmt"
|
||||
|
||||
// Channel represents the ETW logging channel that is used. It can be used by
|
||||
// event consumers to give an event special treatment.
|
||||
type Channel uint8
|
||||
@@ -19,7 +19,11 @@ const (
|
||||
// will always be collected.
|
||||
type Level uint8
|
||||
|
||||
var _ fmt.Stringer = Level(0)
|
||||
|
||||
// Predefined ETW log levels from winmeta.xml in the Windows SDK.
|
||||
//
|
||||
//go:generate go run golang.org/x/tools/cmd/stringer -type=Level -trimprefix=Level
|
||||
const (
|
||||
LevelAlways Level = iota
|
||||
LevelCritical
|
||||
@@ -32,7 +36,11 @@ const (
|
||||
// Opcode represents the operation that the event indicates is being performed.
|
||||
type Opcode uint8
|
||||
|
||||
var _ fmt.Stringer = Opcode(0)
|
||||
|
||||
// Predefined ETW opcodes from winmeta.xml in the Windows SDK.
|
||||
//
|
||||
//go:generate go run golang.org/x/tools/cmd/stringer -type=Opcode -trimprefix=Opcode
|
||||
const (
|
||||
// OpcodeInfo indicates an informational event.
|
||||
OpcodeInfo Opcode = iota
|
||||
@@ -46,7 +54,7 @@ const (
|
||||
OpcodeDCStop
|
||||
)
|
||||
|
||||
// EventDescriptor represents various metadata for an ETW event.
|
||||
// eventDescriptor represents various metadata for an ETW event.
|
||||
type eventDescriptor struct {
|
||||
id uint16
|
||||
version uint8
|
||||
@@ -57,7 +65,7 @@ type eventDescriptor struct {
|
||||
keyword uint64
|
||||
}
|
||||
|
||||
// NewEventDescriptor returns an EventDescriptor initialized for use with
|
||||
// newEventDescriptor returns an EventDescriptor initialized for use with
|
||||
// TraceLogging.
|
||||
func newEventDescriptor() *eventDescriptor {
|
||||
// Standard TraceLogging events default to the TraceLogging channel, and
|
||||
@@ -68,7 +76,7 @@ func newEventDescriptor() *eventDescriptor {
|
||||
}
|
||||
}
|
||||
|
||||
// Identity returns the identity of the event. If the identity is not 0, it
|
||||
// identity returns the identity of the event. If the identity is not 0, it
|
||||
// should uniquely identify the other event metadata (contained in
|
||||
// EventDescriptor, and field metadata). Only the lower 24 bits of this value
|
||||
// are relevant.
|
||||
@@ -78,7 +86,7 @@ func (ed *eventDescriptor) identity() uint32 {
|
||||
return (uint32(ed.version) << 16) | uint32(ed.id)
|
||||
}
|
||||
|
||||
// SetIdentity sets the identity of the event. If the identity is not 0, it
|
||||
// setIdentity sets the identity of the event. If the identity is not 0, it
|
||||
// should uniquely identify the other event metadata (contained in
|
||||
// EventDescriptor, and field metadata). Only the lower 24 bits of this value
|
||||
// are relevant.
|
||||
|
||||
Reference in New Issue
Block a user