logging

package
v0.33.0 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2024 License: Apache-2.0 Imports: 11 Imported by: 10

Documentation

Overview

Package logging implements the logger for the pack CLI.

Package logging defines the minimal interface that loggers must support to be used by client.

Index

Constants

View Source
const (

	// InvalidFileDescriptor based on https://golang.org/src/os/file_unix.go?s=2183:2210#L57
	InvalidFileDescriptor = ^(uintptr(0))
)

Variables

This section is empty.

Functions

func GetWriterForLevel

func GetWriterForLevel(logger Logger, level Level) io.Writer

GetWriterForLevel retrieves the appropriate Writer for the log level provided.

See isSelectableWriter

func IsQuiet

func IsQuiet(logger Logger) bool

IsQuiet defines whether a pack logger is set to quiet mode

func ScanLinesKeepNewLine

func ScanLinesKeepNewLine(data []byte, atEOF bool) (advance int, token []byte, err error)

A customized implementation of bufio.ScanLines that preserves new line characters.

func Tip

func Tip(l Logger, format string, v ...interface{})

Tip logs a tip.

func WithClock

func WithClock(clock func() time.Time) func(writers *LogWithWriters)

WithClock is an option used to initialize a LogWithWriters with a given clock function

func WithVerbose

func WithVerbose() func(writers *LogWithWriters)

WithVerbose is an option used to initialize a LogWithWriters with Verbose turned on

Types

type Level

type Level int
const (
	DebugLevel Level = iota
	InfoLevel
	WarnLevel
	ErrorLevel
)

type LogWithWriters

type LogWithWriters struct {
	sync.Mutex
	log.Logger
	// contains filtered or unexported fields
}

LogWithWriters is a logger used with the pack CLI, allowing users to print logs for various levels, including Info, Debug and Error

func NewLogWithWriters

func NewLogWithWriters(stdout, stderr io.Writer, opts ...func(*LogWithWriters)) *LogWithWriters

NewLogWithWriters creates a logger to be used with pack CLI.

func (*LogWithWriters) HandleLog

func (lw *LogWithWriters) HandleLog(e *log.Entry) error

HandleLog handles log events, printing entries appropriately

func (*LogWithWriters) IsVerbose

func (lw *LogWithWriters) IsVerbose() bool

IsVerbose returns whether verbose logging is on

func (*LogWithWriters) WantQuiet

func (lw *LogWithWriters) WantQuiet(f bool)

WantQuiet reduces the number of logs returned

func (*LogWithWriters) WantTime

func (lw *LogWithWriters) WantTime(f bool)

WantTime turns timestamps on in log entries

func (*LogWithWriters) WantVerbose

func (lw *LogWithWriters) WantVerbose(f bool)

WantVerbose increases the number of logs returned

func (*LogWithWriters) Writer

func (lw *LogWithWriters) Writer() io.Writer

Writer returns the base Writer for the LogWithWriters

func (*LogWithWriters) WriterForLevel

func (lw *LogWithWriters) WriterForLevel(level Level) io.Writer

WriterForLevel returns a Writer for the given Level

type Logger

type Logger interface {
	Debug(msg string)
	Debugf(fmt string, v ...interface{})

	Info(msg string)
	Infof(fmt string, v ...interface{})

	Warn(msg string)
	Warnf(fmt string, v ...interface{})

	Error(msg string)
	Errorf(fmt string, v ...interface{})

	Writer() io.Writer

	IsVerbose() bool
}

Logger defines behavior required by a logging package used by pack libraries

func NewSimpleLogger

func NewSimpleLogger(w io.Writer) Logger

NewSimpleLogger creates a simple logger for the pack library.

type PrefixWriter

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

PrefixWriter is a buffering writer that prefixes each new line. Close should be called to properly flush the buffer.

func NewPrefixWriter

func NewPrefixWriter(w io.Writer, prefix string, opts ...PrefixWriterOption) *PrefixWriter

NewPrefixWriter writes by w will be prefixed

func (*PrefixWriter) Close

func (w *PrefixWriter) Close() error

Close writes any pending data in the buffer

func (*PrefixWriter) Write

func (w *PrefixWriter) Write(data []byte) (int, error)

Write writes bytes to the embedded log function

type PrefixWriterOption

type PrefixWriterOption func(c *PrefixWriter)

func WithReaderFactory

func WithReaderFactory(factory func(data []byte) io.Reader) PrefixWriterOption

Jump to

Keyboard shortcuts

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