From 227bce9a1810fe10247e809f59f9e4e5ad2ed721 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Otto=20Kr=C3=B6pke?= Date: Sun, 23 Jul 2023 10:47:49 +0200 Subject: [PATCH] windows/src/eventlog: Support eventlog events with multiple strings --- windows/svc/eventlog/log.go | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/windows/svc/eventlog/log.go b/windows/svc/eventlog/log.go index f37b4b510..90cfb3eff 100644 --- a/windows/svc/eventlog/log.go +++ b/windows/svc/eventlog/log.go @@ -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...) }