Documentation ¶
Index ¶
- Constants
- Variables
- func Colorize(color, text string) string
- func ColorizeJSON(data []byte) []byte
- func FormatBoolean(b bool) string
- func FormatEventSeverity(severity string) string
- func FormatEventType(eventType string) string
- func FormatNodeID(nodeID string) string
- func FormatTime(t time.Time) string
- func FormatUUID(uuid string) string
- func GetLogger(component string) zerolog.Logger
- func IsFileExists(name string) bool
- func IsSetP[T comparable](v *T) bool
- func LineLogger(logger zerolog.Logger, level zerolog.Level, cb ...func(*zerolog.Event)) func(chan []byte)
- func ParseTime(text string) (time.Time, error)
- func RenderTable(headers []string, populate func(table *tablewriter.Table))
- func RenderTableRows(headers []string, nextRow func() []string)
- func SetLoggingLevel(level zerolog.Level)
- func URLSafe(u *url.URL) *url.URL
- func UnescapeUnicodeCharactersInJSON(_jsonRaw json.RawMessage) (json.RawMessage, error)
- func UserError(msg string, format ...interface{})
- func UserNote(msg string, format ...interface{})
- func UserOutput(msg string, format ...interface{})
- func UserOutputJSON(data []byte)
- func UserWarning(msg string, format ...interface{})
- type TableRenderer
- type TableRow
- type WrappedCmd
- type WriterFunc
Constants ¶
const ( DebugLevel = zerolog.DebugLevel InfoLevel = zerolog.InfoLevel WarnLevel = zerolog.WarnLevel )
Log levels to be used by main, or other entry points in this project
const ( ColorRed = "\033[0;31m" ColorGreen = "\033[0;32m" ColorYellow = "\033[0;33m" ColorBlue = "\033[0;34m" ColorMagenta = "\033[0;35m" ColorCyan = "\033[0;36m" ColorBrightRed = "\033[1;31m" ColorBrightGreen = "\033[1;32m" ColorBrightYellow = "\033[1;33m" ColorBrightBlue = "\033[1;34m" ColorBrightMagenta = "\033[1;35m" ColorBrightCyan = "\033[1;36m" ColorDarkGrey = "\033[1;30m" ColorWhite = "\033[1;37m" ColorReset = "\033[0m" ColorOutput = ColorWhite ColorSuccess = ColorBrightCyan ColorWarning = ColorBrightYellow ColorError = ColorBrightRed )
Variables ¶
var ErrValidationFailed = errors.New("validation error")
var IsColorOutputSupported bool
var WithStderrLogger = func(logger zerolog.Logger, level zerolog.Level, cb ...func(*zerolog.Event)) func(*WrappedCmd) error { return WithStderrReader(LineLogger(logger, level, cb...)) }
var WithStderrReader = func(cb func(lines chan []byte)) func(cmd *WrappedCmd) error { return func(cmd *WrappedCmd) error { stderr, err := cmd.StderrPipe() if err != nil { return err } return cmd.startReader(stderr, cb) } }
WithStderrLogger returns a command option which sends stderr to channel in callback
var WithStdin = func(stdin io.Reader) func(cmd *WrappedCmd) error { return func(cmd *WrappedCmd) error { cmd.Stdin = stdin return nil } }
var WithStdoutLogger = func(logger zerolog.Logger, level zerolog.Level, cb ...func(*zerolog.Event)) func(*WrappedCmd) error { return WithStdoutReader(LineLogger(logger, level, cb...)) }
var WithStdoutReader = func(cb func(lines chan []byte)) func(cmd *WrappedCmd) error { return func(cmd *WrappedCmd) error { stdout, err := cmd.StdoutPipe() if err != nil { return err } return cmd.startReader(stdout, cb) } }
WithStdoutLogger returns a command option which sends stdout to channel in callback
Functions ¶
func ColorizeJSON ¶
func FormatBoolean ¶
func FormatEventSeverity ¶
func FormatEventType ¶
func FormatNodeID ¶
func FormatTime ¶
func FormatUUID ¶
func IsFileExists ¶
func IsSetP ¶
func IsSetP[T comparable](v *T) bool
IsSetP returns true if pointer is not nil and value is not empty
func LineLogger ¶
func RenderTable ¶
func RenderTable(headers []string, populate func(table *tablewriter.Table))
func RenderTableRows ¶
func SetLoggingLevel ¶
SetLoggingLevel should be invoked once by each entry point
func UnescapeUnicodeCharactersInJSON ¶
func UnescapeUnicodeCharactersInJSON(_jsonRaw json.RawMessage) (json.RawMessage, error)
func UserError ¶
func UserError(msg string, format ...interface{})
UserError prints a colorized error message to stderr, and terminates with a non-zero exit code
func UserNote ¶
func UserNote(msg string, format ...interface{})
UserNote prints a colorized info message to stderr. Use this function to output a neutral or positive message to the user.
func UserOutput ¶
func UserOutput(msg string, format ...interface{})
UserOutput prints text to stdout. Use this function to output a command's return value.
func UserOutputJSON ¶
func UserOutputJSON(data []byte)
UserOutputJSON is like UserOutput, but for JSON
func UserWarning ¶
func UserWarning(msg string, format ...interface{})
UserWarning prints a colorized warning message to stderr
Types ¶
type TableRenderer ¶
type TableRenderer struct { Headers []string Populate func(table *tablewriter.Table) }
func (*TableRenderer) Render ¶
func (tr *TableRenderer) Render()
type TableRow ¶
type TableRow struct { Cells []string // contains filtered or unexported fields }
func NewTableRow ¶
type WriterFunc ¶
type WriterFunc struct { *sync.WaitGroup io.Writer io.Closer ErrCloser interface { CloseWithError(err error) error } }
func NewWritterFunc ¶
func NewWritterFunc(readers ...func([]byte)) WriterFunc
NewWritterFunc returns a helper which runs callback for each line, written to WriterFunc