Skip to content

Commit 227bce9

Browse files
committed
windows/src/eventlog: Support eventlog events with multiple strings
1 parent ad7130c commit 227bce9

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

windows/svc/eventlog/log.go

+13-9
Original file line numberDiff line numberDiff line change
@@ -46,25 +46,29 @@ func (l *Log) Close() error {
4646
return windows.DeregisterEventSource(l.Handle)
4747
}
4848

49-
func (l *Log) report(etype uint16, eid uint32, msg string) error {
50-
ss := []*uint16{syscall.StringToUTF16Ptr(msg)}
51-
return windows.ReportEvent(l.Handle, etype, 0, eid, 0, 1, 0, &ss[0], nil)
49+
func (l *Log) report(etype uint16, eid uint32, msgs ...string) error {
50+
var ss []*uint16
51+
52+
for _, msg := range msgs {
53+
ss = append(ss, syscall.StringToUTF16Ptr(msg))
54+
}
55+
return windows.ReportEvent(l.Handle, etype, 0, eid, 0, uint16(len(ss)), 0, &ss[0], nil)
5256
}
5357

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

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

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

0 commit comments

Comments
 (0)