sink

package
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package sink defines the final destinations for processed log messages. It supports multiple output types like the terminal console and physical files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConsoleSink

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

ConsoleSink writes formatted log messages directly to standard output (Stdout).

func NewConsoleSink

func NewConsoleSink(f formatter.Formatter) *ConsoleSink

NewConsoleSink creates a new ConsoleSink with the specified formatter.

func (*ConsoleSink) Close

func (s *ConsoleSink) Close() error

Close is a no-op for the console sink.

func (*ConsoleSink) Write

func (s *ConsoleSink) Write(msg types.LogMessage) error

Write outputs the message to the console.

type FileSink

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

FileSink persists log messages to a physical file on disk.

func NewFileSink

func NewFileSink(path string, f formatter.Formatter) (*FileSink, error)

NewFileSink opens or creates a file at the specified path for appending logs.

func (*FileSink) Close

func (s *FileSink) Close() error

Close closes the underlying file handle.

func (*FileSink) Write

func (s *FileSink) Write(msg types.LogMessage) error

Write appends the formatted message to the end of the file.

type MultiSink

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

MultiSink allows broadcasting a single log message to multiple destinations. This is used when logs need to be simultaneously printed to the screen and persisted to a file.

func NewMultiSink

func NewMultiSink(sinks ...Sink) *MultiSink

NewMultiSink creates a composite sink from a variadic list of sinks.

func (*MultiSink) Close

func (m *MultiSink) Close() error

Close gracefully shuts down all child sinks.

func (*MultiSink) Write

func (m *MultiSink) Write(msg types.LogMessage) error

Write delivers the message to all child sinks. If any sink fails, it returns the error immediately.

type Sink

type Sink interface {
	// Write formats and delivers the log message to the underlying destination.
	Write(msg types.LogMessage) error
	// Close performs any necessary cleanup (e.g., closing file handles).
	Close() error
}

Sink defines the contract for any component that serves as a final destination for log messages. Sinks are responsible for the physical writing of formatted strings to their respective backends.

Jump to

Keyboard shortcuts

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