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 should be registered on the target machine (for example by an MSI/WiX installer, or via eventlog.InstallAsEventCreate at install time). If it isn't, events are still written to the Application log, but Event Viewer can't show their descriptions. This handler only opens and writes to a 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. Carriage returns and line feeds in the message, keys and values are written as \r and \n, so a value can't add lines that look like other attributes.
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.