slogntfy

package module
v0.0.0-...-d9cbe0f Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2025 License: MIT Imports: 10 Imported by: 0

README

slog-ntfy

A ntfy Handler for slog.

Install

go get git.ntwrk.space/mmaths/slog-ntfy

License

This package is distributed under the MIT license found in the LICENSE file.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type NtfyHandler

type NtfyHandler struct {
	// contains filtered or unexported fields
}

NtfyHandler is a slog.Handler that sends log messages to a ntfy server.

func New

func New(opts *Options) *NtfyHandler

New creates a new NtfyHandler from the provided options.

func (*NtfyHandler) Enabled

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

Enabled reports whether the handler handles records at the given level.

func (*NtfyHandler) Handle

func (h *NtfyHandler) Handle(ctx context.Context, r slog.Record) error

Handle handles the Record.

func (*NtfyHandler) WithAttrs

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

WithAttrs returns a new Handler whose attributes consist of both the receiver's attributes and the arguments.

func (*NtfyHandler) WithGroup

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

WithGroup returns a new Handler with the given group appended to the receiver's existing groups.

type Options

type Options struct {
	// AddSource causes the handler to compute the source code position
	// of the log statement and add a SourceKey attribute to the output.
	AddSource bool

	// Level reports the minimum record level that will be logged.
	Level slog.Leveler

	// Server is the server address for the ntfy service.
	Server string

	// Topic is the topic name for the ntfy service.
	Topic string

	// Token is the authentication token for the ntfy service.
	Token string
}

Jump to

Keyboard shortcuts

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