outz

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2024 License: MIT Imports: 15 Imported by: 4

Documentation

Overview

Package outz provides various utilities for styling, formatting, and capturing output.

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultStyles = defaultStyles
)

DefaultStyles is a default, shared instance of Styles.

Functions

func MustBeginOutputCapture

func MustBeginOutputCapture(outputSetupFuncs ...OutputSetupFunc)

MustBeginOutputCapture sets up the mock streams and starts capturing the output. It panics if another output capture is already in progress. It is the caller's responsibility to ensure mutual exclusion.

func MustEndOutputCapture

func MustEndOutputCapture() (string, string)

MustEndOutputCapture restores the real streams and returns the captured data. It panics if no output capture is in progress.

func NewLogger

func NewLogger() *logrus.Logger

NewLogger initializes new *logrus.Logger and registers it for possible output caputre.

func ResetOutputCapture

func ResetOutputCapture()

ResetOutputCapture ensures the output capture is cleared and reset (e.g. after a panic, error or test assertion that prevents MustEndOutputCapture from being called). Always defer ResetOutputCapture before using output captures.

func RestoreDefaultStyles

func RestoreDefaultStyles()

RestoreDefaultStyles restores the default value of DefaultStyles.

Types

type HumanLogFormatter

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

HumanLogFormatter is a human-readable logrus.Formatter suitable for colored, interactive console output.

func NewHumanLogFormatter

func NewHumanLogFormatter() *HumanLogFormatter

NewHumanLogFormatter initializes a new *HumanLogFormatter.

func (*HumanLogFormatter) Format

func (f *HumanLogFormatter) Format(entry *logrus.Entry) ([]byte, error)

Format implements the logrus.Formatter interface.

func (*HumanLogFormatter) SetInitTime

func (f *HumanLogFormatter) SetInitTime(initTime time.Time) *HumanLogFormatter

SetInitTime sets the init time.Time.

func (*HumanLogFormatter) SetStyles

func (f *HumanLogFormatter) SetStyles(styles Styles) *HumanLogFormatter

SetStyles sets the Styles.

type OutputRestoreFunc

type OutputRestoreFunc func()

OutputRestoreFunc describe a function that restores some real streams after capturing.

func OutputSetupRodaineTable

func OutputSetupRodaineTable(outW *os.File, _ *os.File) OutputRestoreFunc

OutputSetupRodaineTable is a OutputSetupFunc that configures the table streams (from "github.com/rodaine/table").

func OutputSetupSirupsenLogrus

func OutputSetupSirupsenLogrus(_ *os.File, errW *os.File) OutputRestoreFunc

OutputSetupSirupsenLogrus is a OutputSetupFunc that configures the logging streams (from "github.com/sirupsen/logrus").

func OutputSetupStandard

func OutputSetupStandard(outW *os.File, errW *os.File) OutputRestoreFunc

OutputSetupStandard is a OutputSetupFunc that configures the stdout/stderr streams.

type OutputSetupFunc

type OutputSetupFunc func(outW *os.File, errW *os.File) OutputRestoreFunc

OutputSetupFunc describes a function that replaces some streams with mock ones for capturing.

func GetOutputSetupFatihColor

func GetOutputSetupFatihColor(noColor bool) OutputSetupFunc

GetOutputSetupFatihColor returns a OutputSetupFunc that configures the color streams (from "github.com/fatih/color").

type Styles

type Styles interface {
	Default() *color.Color
	Highlight() *color.Color
	SecondaryHighlight() *color.Color
	Secondary() *color.Color
	Info() *color.Color
	Success() *color.Color
	Warning() *color.Color
	Error() *color.Color
	LogLevel(level logrus.Level) *color.Color
}

Styles describes a set of output styles.

Jump to

Keyboard shortcuts

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