clog

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2024 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterHook

func RegisterHook(hook Hook)

func RemoveHook

func RemoveHook(hook Hook)

Types

type Hook

type Hook interface {
	// Called when a logger is writing a line.
	// The line is already formatted.
	Write(ns string, line string, kind Stream)
}

Hooking system to inject listeners into all loggers.

type Logger

type Logger struct {
	Handles   [StreamMax]*os.File
	Paths     [StreamMax]string
	Opened    Stream
	Timestamp string
	Namespace string
	PfxWidth  int
	// contains filtered or unexported fields
}

func FromContext

func FromContext(ctx context.Context) *Logger

func New

func New(prev *Logger, opts Options) (r *Logger, err error)

func (*Logger) Close

func (logger *Logger) Close()

func (*Logger) Flush

func (logger *Logger) Flush()

func (*Logger) Fork

func (logger *Logger) Fork(ns string) (r *Logger)

func (*Logger) Printf

func (logger *Logger) Printf(format string, args ...any) (n int, err error)

func (*Logger) Stderr

func (logger *Logger) Stderr() io.Writer

func (*Logger) Stdout

func (logger *Logger) Stdout() io.Writer

func (*Logger) Sync

func (logger *Logger) Sync()

func (*Logger) Tail

func (logger *Logger) Tail(numLines int, stream Stream) (out []string, err error)

func (*Logger) WithContext

func (logger *Logger) WithContext(ctx context.Context) context.Context

type Options

type Options struct {
	Output   string `json:"stdout,omitempty"`    // The file to which to redirect stdout, "null" to discard.
	Error    string `json:"stderr,omitempty"`    // The file to which to redirect stderr, "null" to discard, "merge" to redirect to stdout.
	LogTime  string `json:"log_time,omitempty"`  // The format to use for timestamps.
	LogName  string `json:"log_name,omitempty"`  // The name to prepend to log lines.
	PfxWidth int    `json:"pfx_width,omitempty"` // The width of the prefix.
}

type Stream

type Stream uint8
const (
	StreamStdout Stream = iota
	StreamStderr
	StreamMax
)

func (Stream) String

func (str Stream) String() string

type Writer

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

Writer type to wrap an io.Writer with the processing.

func (*Writer) Flush

func (f *Writer) Flush() (e error)

func (*Writer) Write

func (f *Writer) Write(input []byte) (n int, err error)

func (*Writer) WritePrefix

func (f *Writer) WritePrefix()

Jump to

Keyboard shortcuts

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