winevent

package
v0.25.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 16, 2026 License: Apache-2.0 Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Rendered for windows/amd64

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

func NewHandler(source string, opts *Options) (*Handler, error)

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.

func (*Handler) Close

func (h *Handler) Close() error

Close deregisters the handler's underlying event source handle.

func (*Handler) Enabled

func (h *Handler) Enabled(_ context.Context, level slog.Level) bool

Enabled implements slog.Handler.

func (*Handler) Handle

func (h *Handler) Handle(_ context.Context, r slog.Record) error

Handle implements slog.Handler.

func (*Handler) WithAttrs

func (h *Handler) WithAttrs(attrs []slog.Attr) slog.Handler

WithAttrs implements slog.Handler.

func (*Handler) WithGroup

func (h *Handler) WithGroup(name string) slog.Handler

WithGroup implements slog.Handler.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL