Skip to content

Commit

Permalink
windows/src/eventlog: Support eventlog events with multiple strings
Browse files Browse the repository at this point in the history
  • Loading branch information
jkroepke committed Jul 23, 2023
1 parent ad7130c commit 227bce9
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions windows/svc/eventlog/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,29 @@ func (l *Log) Close() error {
return windows.DeregisterEventSource(l.Handle)
}

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)
func (l *Log) report(etype uint16, eid uint32, msgs ...string) error {
var ss []*uint16

for _, msg := range msgs {
ss = append(ss, syscall.StringToUTF16Ptr(msg))
}
return windows.ReportEvent(l.Handle, etype, 0, eid, 0, uint16(len(ss)), 0, &ss[0], nil)
}

// Info writes an information event msg with event id eid to the end of event log l.
// When EventCreate.exe is used, eid must be between 1 and 1000.
func (l *Log) Info(eid uint32, msg string) error {
return l.report(windows.EVENTLOG_INFORMATION_TYPE, eid, msg)
func (l *Log) Info(eid uint32, msgs ...string) error {
return l.report(windows.EVENTLOG_INFORMATION_TYPE, eid, msgs...)
}

// Warning writes an warning event msg with event id eid to the end of event log l.
// When EventCreate.exe is used, eid must be between 1 and 1000.
func (l *Log) Warning(eid uint32, msg string) error {
return l.report(windows.EVENTLOG_WARNING_TYPE, eid, msg)
func (l *Log) Warning(eid uint32, msgs ...string) error {
return l.report(windows.EVENTLOG_WARNING_TYPE, eid, msgs...)
}

// Error writes an error event msg with event id eid to the end of event log l.
// When EventCreate.exe is used, eid must be between 1 and 1000.
func (l *Log) Error(eid uint32, msg string) error {
return l.report(windows.EVENTLOG_ERROR_TYPE, eid, msg)
func (l *Log) Error(eid uint32, msgs ...string) error {
return l.report(windows.EVENTLOG_ERROR_TYPE, eid, msgs...)
}

0 comments on commit 227bce9

Please sign in to comment.