mirror of
https://github.com/rwinkhart/go-winio.git
synced 2026-08-28 04:46:50 -04:00
Change from reflection to type switch in Logrus hook
This commit is contained in:
@@ -8,7 +8,8 @@ import (
|
||||
// InType indicates the type of data contained in the ETW event.
|
||||
type InType byte
|
||||
|
||||
// Various InType definitions for TraceLogging.
|
||||
// Various InType definitions for TraceLogging. These must match the definitions
|
||||
// found in TraceLoggingProvider.h in the Windows SDK.
|
||||
const (
|
||||
InTypeNull InType = iota
|
||||
InTypeUnicodeString
|
||||
|
||||
@@ -57,10 +57,10 @@ func (h *Hook) Fire(e *logrus.Entry) error {
|
||||
event.Data.AddString(e.Message)
|
||||
|
||||
for k, v := range e.Data {
|
||||
switch reflect.TypeOf(v).Kind() {
|
||||
case reflect.String:
|
||||
switch v := v.(type) {
|
||||
case string:
|
||||
event.Metadata.AddField(k, etw.InTypeAnsiString)
|
||||
event.Data.AddString(v.(string))
|
||||
event.Data.AddString(v)
|
||||
default:
|
||||
event.Metadata.AddField(k, etw.InTypeAnsiString)
|
||||
event.Data.AddString(fmt.Sprintf("<unknown type: %v> %v", reflect.TypeOf(v), v))
|
||||
|
||||
Reference in New Issue
Block a user