syslog

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2026 License: MIT Imports: 6 Imported by: 0

README

Syslog

Syslog wrapper that implements slog.Handler.

Usage

handler, err := syslog.NewHandler(slog.LevelInfo, "", "", syslog.LOG_INFO|syslog.LOG_USER, "your-tag")
if err != nil {
    return err
}
defer handler.Close()

logger := slog.New(handler)
slog.SetDefault(logger)

Documentation

Overview

Syslog wrapper that implements slog.Handler.

Version: 0.0.1. Repository: https://github.com/ordinary-dev/go-sfl. License: MIT.

Index

Constants

View Source
const (
	LOG_EMERG   = syslog.LOG_EMERG
	LOG_ALERT   = syslog.LOG_ALERT
	LOG_CRIT    = syslog.LOG_CRIT
	LOG_ERR     = syslog.LOG_ERR
	LOG_WARNING = syslog.LOG_WARNING
	LOG_NOTICE  = syslog.LOG_NOTICE
	LOG_INFO    = syslog.LOG_INFO
	LOG_DEBUG   = syslog.LOG_DEBUG
)
View Source
const (
	LOG_KERN     = syslog.LOG_KERN
	LOG_USER     = syslog.LOG_USER
	LOG_MAIL     = syslog.LOG_MAIL
	LOG_DAEMON   = syslog.LOG_DAEMON
	LOG_AUTH     = syslog.LOG_AUTH
	LOG_SYSLOG   = syslog.LOG_SYSLOG
	LOG_LPR      = syslog.LOG_LPR
	LOG_NEWS     = syslog.LOG_NEWS
	LOG_UUCP     = syslog.LOG_UUCP
	LOG_CRON     = syslog.LOG_CRON
	LOG_AUTHPRIV = syslog.LOG_AUTHPRIV
	LOG_FTP      = syslog.LOG_FTP

	LOG_LOCAL0 = syslog.LOG_LOCAL0
	LOG_LOCAL1 = syslog.LOG_LOCAL1
	LOG_LOCAL2 = syslog.LOG_LOCAL2
	LOG_LOCAL3 = syslog.LOG_LOCAL3
	LOG_LOCAL4 = syslog.LOG_LOCAL4
	LOG_LOCAL5 = syslog.LOG_LOCAL5
	LOG_LOCAL6 = syslog.LOG_LOCAL6
	LOG_LOCAL7 = syslog.LOG_LOCAL7
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

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

func NewHandler

func NewHandler(level slog.Level, network, raddr string, priority Priority, tag string) (*Handler, error)

Create a new syslog handler.

See the log/syslog documentation for information on the network, raddr, priority and tag parameters. Caller must call Close() when the handler is no longer needed.

Usage:

handler, err := syslog.NewSysLogHandler(slog.LevelInfo, "", "", syslog.LOG_INFO|syslog.LOG_USER, "my-program")
if err != nil {
    return err
}
defer handler.Close()

logger := slog.New(handler)
slog.SetDefault(logger)

func (*Handler) Close

func (s *Handler) Close() error

func (*Handler) Enabled

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

Enabled reports whether the handler handles records at the given level. The handler ignores records whose level is lower. It is called early, before any arguments are processed, to save effort if the log event should be discarded. If called from a Logger method, the first argument is the context passed to that method, or context.Background() if nil was passed or the method does not take a context. The context is passed so Enabled can use its values to make a decision.

func (*Handler) Handle

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

Handle handles the Record. It will only be called when Enabled returns true. The Context argument is as for Enabled. It is present solely to provide Handlers access to the context's values. Canceling the context should not affect record processing. (Among other things, log messages may be necessary to debug a cancellation-related problem.)

Handle methods that produce output should observe the following rules:

  • If r.Time is the zero time, ignore the time.
  • If r.PC is zero, ignore it.
  • Attr's values should be resolved.
  • If an Attr's key and value are both the zero value, ignore the Attr. This can be tested with attr.Equal(Attr{}).
  • If a group's key is empty, inline the group's Attrs.
  • If a group has no Attrs (even if it has a non-empty key), ignore it.

[Logger] discards any errors from Handle. Wrap the Handle method to process any errors from Handlers.

func (*Handler) WithAttrs

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

WithAttrs returns a new Handler whose attributes consist of both the receiver's attributes and the arguments. The Handler owns the slice: it may retain, modify or discard it.

func (*Handler) WithGroup

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

WithGroup returns a new Handler with the given group appended to the receiver's existing groups. The keys of all subsequent attributes, whether added by With or in a Record, should be qualified by the sequence of group names.

How this qualification happens is up to the Handler, so long as this Handler's attribute keys differ from those of another Handler with a different sequence of group names.

A Handler should treat WithGroup as starting a Group of Attrs that ends at the end of the log event. That is,

logger.WithGroup("s").LogAttrs(ctx, level, msg, slog.Int("a", 1), slog.Int("b", 2))

should behave like

logger.LogAttrs(ctx, level, msg, slog.Group("s", slog.Int("a", 1), slog.Int("b", 2)))

If the name is empty, WithGroup returns the receiver.

type Priority

type Priority = syslog.Priority

Export constants from log/syslog.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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