Documentation
¶
Overview ¶
Package winevent provides an slog.Handler that writes log records to the Windows Event Log via golang.org/x/sys/windows/svc/eventlog.
The named event source must already be registered on the target machine (for example by an MSI/WiX installer, via New-EventLog in PowerShell, or via eventlog.InstallAsEventCreate at install time) before NewHandler is called. This handler only opens and writes to an existing source; it does not register or deregister one.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler is an slog.Handler that writes records to the Windows Event Log.
Record level is mapped to Windows event type as follows:
level < slog.LevelWarn -> eventlog.Info level < slog.LevelError -> eventlog.Warning level >= slog.LevelError -> eventlog.Error
Structured attributes and groups are rendered as an indented "key: value" list appended below the log message, one per line, which is more readable in Event Viewer than a single logfmt/JSON line.
func NewHandler ¶
NewHandler returns a Handler that writes to the already-registered Windows Event Log source named by source. The caller is responsible for calling Close on the returned Handler when done.
type Options ¶
type Options struct {
// Level is the minimum record level that will be logged.
// If nil, the handler defaults to slog.LevelInfo.
Level slog.Leveler
// EventID is the Windows event ID reported with every record.
// If zero, it defaults to 1.
EventID uint32
// AddSource causes the handler to append the source file and line
// of the log call as a "source: file:line" line.
AddSource bool
}
Options configures a Handler.