logging

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

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 WithSelectableWriter

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.

Types

type Level

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

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 New

func New(w io.Writer) Logger

New creates a default logger for the pack library. Note that the pack CLI has it's own logger.

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

type WithSelectableWriter

type WithSelectableWriter interface {
	WriterForLevel(level Level) io.Writer
}

WithSelectableWriter is an optional interface for loggers that want to support a separate writer per log level.

Jump to

Keyboard shortcuts

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