flog

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2022 License: MIT Imports: 5 Imported by: 11

README

flog

flog is a minimal, formatted, pretty logging package for Go.

It's optimized for human readability and CLIs.

  • Log levels color-code the timestamp
  • Log level doesn't change the width of the prefix

slog is recommended for robust logging.

GoDoc

Install

go get github.com/coder/flog

Usage

flog.Infof("hello %.3f", 1/3.0)
flog.Successf("finished that")
flog.Errorf("oops")

log := flog.New(os.Stderr).WithPrefix("user %v: ", 500)

log.Errorf("didn't work out")

Output

example

Documentation

Overview

Package flog provides human-optimized, formatted logging.

Index

Constants

View Source
const (
	ClockFormat     = "15:04:05"
	DateClockFormat = "2006-01-02" + ClockFormat
)

Time formats

Variables

This section is empty.

Functions

func Errorf added in v1.1.0

func Errorf(msg string, args ...interface{})

func Fatalf added in v1.1.0

func Fatalf(msg string, args ...interface{})

func Infof added in v1.1.0

func Infof(msg string, args ...interface{})

func Successf added in v1.1.0

func Successf(msg string, args ...interface{})

Types

type Logger

type Logger struct {
	W          io.Writer
	TimeFormat string
	Prefix     string
}

func New

func New(w io.Writer) *Logger

New returns a new logger.

func (*Logger) Error

func (l *Logger) Error(msg string, args ...interface{})

func (*Logger) Fatal

func (l *Logger) Fatal(msg string, args ...interface{})

func (*Logger) Info

func (l *Logger) Info(msg string, args ...interface{})

func (*Logger) Success

func (l *Logger) Success(msg string, args ...interface{})

func (*Logger) WithPrefix

func (l *Logger) WithPrefix(p string, args ...interface{}) *Logger

Jump to

Keyboard shortcuts

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