eventopt.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. //go:build windows
  2. // +build windows
  3. package etw
  4. import (
  5. "github.com/Microsoft/go-winio/pkg/guid"
  6. )
  7. type eventOptions struct {
  8. descriptor *eventDescriptor
  9. activityID guid.GUID
  10. relatedActivityID guid.GUID
  11. tags uint32
  12. }
  13. // EventOpt defines the option function type that can be passed to
  14. // Provider.WriteEvent to specify general event options, such as level and
  15. // keyword.
  16. type EventOpt func(options *eventOptions)
  17. // WithEventOpts returns the variadic arguments as a single slice.
  18. func WithEventOpts(opts ...EventOpt) []EventOpt {
  19. return opts
  20. }
  21. // WithLevel specifies the level of the event to be written.
  22. func WithLevel(level Level) EventOpt {
  23. return func(options *eventOptions) {
  24. options.descriptor.level = level
  25. }
  26. }
  27. // WithKeyword specifies the keywords of the event to be written. Multiple uses
  28. // of this option are OR'd together.
  29. func WithKeyword(keyword uint64) EventOpt {
  30. return func(options *eventOptions) {
  31. options.descriptor.keyword |= keyword
  32. }
  33. }
  34. // WithChannel specifies the channel of the event to be written.
  35. func WithChannel(channel Channel) EventOpt {
  36. return func(options *eventOptions) {
  37. options.descriptor.channel = channel
  38. }
  39. }
  40. // WithOpcode specifies the opcode of the event to be written.
  41. func WithOpcode(opcode Opcode) EventOpt {
  42. return func(options *eventOptions) {
  43. options.descriptor.opcode = opcode
  44. }
  45. }
  46. // WithTags specifies the tags of the event to be written. Tags is a 28-bit
  47. // value (top 4 bits are ignored) which are interpreted by the event consumer.
  48. func WithTags(newTags uint32) EventOpt {
  49. return func(options *eventOptions) {
  50. options.tags |= newTags
  51. }
  52. }
  53. // WithActivityID specifies the activity ID of the event to be written.
  54. func WithActivityID(activityID guid.GUID) EventOpt {
  55. return func(options *eventOptions) {
  56. options.activityID = activityID
  57. }
  58. }
  59. // WithRelatedActivityID specifies the parent activity ID of the event to be written.
  60. func WithRelatedActivityID(activityID guid.GUID) EventOpt {
  61. return func(options *eventOptions) {
  62. options.relatedActivityID = activityID
  63. }
  64. }