syslog

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Tag is the application identifier (max 32 chars, will be truncated if longer).
	// Default: "golang-app"
	Tag string

	// Facility is the syslog facility (e.g., syslog.LOG_USER, syslog.LOG_LOCAL0).
	// Default: syslog.LOG_USER
	Facility syslog.Priority

	// Priority is the optional initial priority (defaults to syslog.LOG_INFO).
	// Default: syslog.LOG_INFO
	Priority syslog.Priority

	// Network is the network protocol for remote syslog ("tcp", "tcp4", "tcp6", "udp", "udp4", "udp6").
	// If set, connects to remote syslog; otherwise, uses local.
	// Default: "" (local)
	Network string

	// Addr is the remote address for syslog (e.g., "logs.example.com:514").
	// Required if Network is set.
	// Default: ""
	Addr string
}

Config holds configuration for Syslog handler.

type Option

type Option func(*Config)

Option is a function that modifies Config.

func WithFacility

func WithFacility(facility syslog.Priority) Option

WithFacility sets the syslog facility.

func WithPriority

func WithPriority(priority syslog.Priority) Option

WithPriority sets the initial priority.

func WithRemote

func WithRemote(network, addr string) Option

WithRemote sets the network and address for remote syslog.

func WithTag

func WithTag(tag string) Option

WithTag sets the application tag/ident.

type Syslog

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

Syslog is an lx.Handler that sends log entries to the system syslog daemon. It integrates with the local syslog service (via Unix sockets or network) and maps log levels to appropriate syslog priority levels. This handler is useful for applications that need to integrate with system monitoring tools or centralized log management solutions.

The handler supports: - Automatic level mapping (lx.LevelType to syslog.Priority) - Configurable tag/ident for log identification - Both local and remote syslog destinations - Structured fields as part of log message

Example:

handler, err := syslog.New(
  syslog.WithTag("myapp"),
  syslog.WithFacility(syslog.LOG_LOCAL0),
)
if err != nil {
  log.Fatal(err)
}
logger := ll.New("app").Enable().Handler(handler)
logger.Info("Application started") // Sent to syslog

func New

func New(opts ...Option) (*Syslog, error)

New creates a new Syslog handler based on the provided options. It connects to either local or remote syslog depending on configuration. Returns a configured Syslog or an error if connection fails.

Example:

handler, err := syslog.New(
  syslog.WithTag("my-service"),
  syslog.WithFacility(syslog.LOG_LOCAL0),
  syslog.WithRemote("tcp", "logs.company.com:6514"),
)
if err != nil {
  return err
}

func (*Syslog) Close

func (h *Syslog) Close() error

Close closes the connection to the syslog daemon. It should be called when the handler is no longer needed to release system resources. Returns nil if successful, or an error if the close operation fails.

func (*Syslog) Handle

func (h *Syslog) Handle(e *lx.Entry) error

Handle implements the lx.Handler interface for Syslog. It receives log entries, maps lx log levels to syslog priorities, formats the message with namespace and fields, and sends it to syslog. Thread-safe via the underlying syslog.Writer implementation.

Returns nil on successful delivery, or an error if syslog write fails.

Example (internal usage):

handler.Handle(&lx.Entry{Message: "error occurred", Level: lx.LevelError})

func (*Syslog) Timestamped

func (h *Syslog) Timestamped(enable bool, format ...string)

Timestamped implements the lx.Timestamper interface. This is a no-op for Syslog handler since timestamps are handled by syslog. The method exists for interface compatibility.

Parameters: - enable: Ignored - format: Ignored

Jump to

Keyboard shortcuts

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