microsoft / go-winio

Win32 IO-related utilities for Go
MIT License
946 stars 180 forks source link

Add WriteEventString function. #263

Closed helsaawy closed 1 year ago

helsaawy commented 1 year ago

This is an implementation of #262.

Adds a (*Provider).WriteEventString to write a single string to ETW Since the intent is to add an intermediary function for Moby to call while they transition to this library, the function is marked as deprecated, to ward against future use.

Signed-off-by: Hamza El-Saawy hamzaelsaawy@microsoft.com

helsaawy commented 1 year ago

@thaJeztah @kevpar

kevpar commented 1 year ago

This seems very application-specific to moby. Rather than add an already-deprecated function here, wouldn't it be easier for moby to just define their own function and use that while transitioning to structured logging?

func WriteEventString(p *etw.Provider, m string) error {
    return p.WriteEvent("StringMessage", []etw.EventOpt{etw.WithLevel(0)}, []etw.FieldOpt{etw.StringField("message", m)})
}
helsaawy commented 1 year ago

@thaJeztah Would you be able to do something like below in moby as an interim until you fully transition?

type Provide struct {
  *etw.Provider
}

func (p *etw.Provider) WriteEventString(m string) error {
    return p.WriteEvent("StringMessage", []etw.EventOpt{etw.WithLevel(0)}, []etw.FieldOpt{etw.StringField("message", m)})
}
thaJeztah commented 1 year ago

Thanks for the suggestions! Yes, if we can do it without changes here, that'd definitely be fine with me.

I'm at KubeCon this week, so limited time at my computer. Will try to get back to that soon (if not, please give me a "ping" ☺️😅

helsaawy commented 1 year ago

Okay, I'll close this then. In the meantime; enjoy kubecon :)