log

package
v2.0.0-alpha.2 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2023 License: Apache-2.0 Imports: 4 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DirectoryContentFormatter

type DirectoryContentFormatter interface {
	// File takes the full path and os.FileInfo and returns a display string
	File(path string, info os.FileInfo) (string, error)

	// RootPath provides the root path being iterated
	RootPath(path string)

	// Title provides a plain string title which can be embellished
	Title(title string) string
}

DirectoryContentFormatter allows customization of logged directory output

When libcnb logs the contents of a directory, each item in the directory is passed through a DirectoryContentFormatter.

DirectoryContentsWriter implements this workflow:

  • call RootPath(string) with the root path that's being walked
  • call Title(string) with the given title, the output is logged
  • for each file in the directory:
  • call File(string, os.FileInfo), the output is logged

A default implementation is provided that returns a formatter applies no formatting

The returned formatter operates as such:

Title -> returns string followed by `:\n`
File  -> returns file name relative to the root followed by `\n`

A buildpack author could provide their own implementation through WithDirectoryContentFormatter when calling Detect or Build.

A custom implementation might log in color or might log additional information about each file, like permissions. The implementation can also control line endings to force all of the files to be logged on a single line, or as multiple lines.

type Logger

type Logger interface {
	// Debug formats using the default formats for its operands
	Debug(a ...interface{})

	// Debugf formats according to a format specifier
	Debugf(format string, a ...interface{})

	// DebugWriter returns the configured debug writer
	DebugWriter() io.Writer

	// IsDebugEnabled indicates whether debug logging is enabled
	IsDebugEnabled() bool
}

Logger is the interface implement by a type that wishes to write log messages generated by libcnb

type PlainLogger

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

PlainLogger implements Logger and logs messages to a writer.

func New

func New(debug io.Writer) PlainLogger

New creates a new instance of PlainLogger. It configures debug logging if $BP_DEBUG or $BP_LOG_LEVEL are set.

func NewDiscard

func NewDiscard() PlainLogger

NewDiscard creates a new instance of PlainLogger that discards all log messages. Useful in testing.

func (PlainLogger) Debug

func (l PlainLogger) Debug(a ...interface{})

Debug formats using the default formats for its operands and writes to the configured debug writer. Spaces are added between operands when neither is a string.

func (PlainLogger) DebugWriter

func (l PlainLogger) DebugWriter() io.Writer

DebugWriter returns the configured debug writer.

func (PlainLogger) Debugf

func (l PlainLogger) Debugf(format string, a ...interface{})

Debugf formats according to a format specifier and writes to the configured debug writer.

func (PlainLogger) IsDebugEnabled

func (l PlainLogger) IsDebugEnabled() bool

IsDebugEnabled indicates whether debug logging is enabled.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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