// Report write an event message with event type etype and event ID eid to the // end of event log l. // etype should be one of Info, Success, Warning, Error, AuditSuccess, or AuditFailure. // When EventCreate.exe is used, eid must be between 1 and 1000. func (l *Log) Report(etype uint16, eid uint32, msgs []string) error { var msgPtrs []*uint16 for _, msg := range msgs { msgPtrs = append(msgPtrs, syscall.StringToUTF16Ptr(msg)) } return windows.ReportEvent(l.Handle, etype, 0, eid, 0, uint16(len(msgPtrs)), 0, &msgPtrs[0], nil) }
func (h *etwHook) Fire(e *logrus.Entry) error { var ( etype uint16 eid uint32 ) switch e.Level { case logrus.PanicLevel: etype = windows.EVENTLOG_ERROR_TYPE eid = eventPanic case logrus.FatalLevel: etype = windows.EVENTLOG_ERROR_TYPE eid = eventFatal case logrus.ErrorLevel: etype = windows.EVENTLOG_ERROR_TYPE eid = eventError case logrus.WarnLevel: etype = windows.EVENTLOG_WARNING_TYPE eid = eventWarn case logrus.InfoLevel: etype = windows.EVENTLOG_INFORMATION_TYPE eid = eventInfo case logrus.DebugLevel: etype = windows.EVENTLOG_INFORMATION_TYPE eid = eventDebug default: return errors.New("unknown level") } // If there is additional data, include it as a second string. exts := "" if len(e.Data) > 0 { fs := bytes.Buffer{} for k, v := range e.Data { fs.WriteString(k) fs.WriteByte('=') fmt.Fprint(&fs, v) fs.WriteByte(' ') } exts = fs.String()[:fs.Len()-1] eid += eventExtraOffset } if h.log == nil { fmt.Fprintf(os.Stderr, "%s [%s]\n", e.Message, exts) return nil } var ( ss [2]*uint16 err error ) ss[0], err = syscall.UTF16PtrFromString(e.Message) if err != nil { return err } count := uint16(1) if exts != "" { ss[1], err = syscall.UTF16PtrFromString(exts) if err != nil { return err } count++ } return windows.ReportEvent(h.log.Handle, etype, 0, eid, 0, count, 0, &ss[0], nil) }
func (l *Log) report(etype uint16, eid uint32, msg string) error { ss := []*uint16{syscall.StringToUTF16Ptr(msg)} return windows.ReportEvent(l.Handle, etype, 0, eid, 0, 1, 0, &ss[0], nil) }