loggie

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2019 License: MIT Imports: 8 Imported by: 1

README

Simple unstructured leveled logging.

GoDoc Build Status

Installation

go get -u syreclabs.com/go/loggie

Usage

import "syreclabs.com/go/loggie"

var log = loggie.New("mylogger")

func main() {
    log.Debug("debug message")
    log.Infof("info: %s", time.Now())
    log.Printf(loggie.Lwarning, "warning: %d", 42)
}

Output:

2018/06/06 08:59:29.639 DBG mylogger debug message
2018/06/06 08:59:29.639 INF mylogger info: 2018-06-06 08:59:29.639226176 -0500 -05 m=+0.000262528
2018/06/06 08:59:29.639 WRN mylogger warning: 42

Documentation

Overview

Package loggie provides simple unstructured leveled logging.

Index

Constants

View Source
const (
	Fdate = 1 << iota
	Ftime
	Fmilliseconds
	Futc
	Flevel
	Fname
	Fcolor
	Fdefault = Fdate | Ftime | Fmilliseconds | Flevel | Fname
)

These flags define which info will be included to each entry generated by the logger. By default, all logging entries are prefixed by date, time, level and logger name.

View Source
const (
	Ldebug = iota
	Linfo
	Lwarning
	Lerror
	Lfatal
	Lpanic
	Lnone
)

Known logging levels. Setting logging level to Lnone silences all logging output (including Fatal and Panic logging).

Variables

View Source
var (
	Cdate = "\033[0;37m"
	Ctime = "\033[0;37m"
	Cname = "\033[0;35m"
)

Colors for date, time and logger name fields.

View Source
var Mlevel = map[int][2]string{
	Ldebug:   {"DBG", "\033[97;42m"},
	Linfo:    {"INF", "\033[97;44m"},
	Lwarning: {"WRN", "\033[97;43m"},
	Lerror:   {"ERR", "\033[97;41m"},
	Lfatal:   {"FTL", "\033[97;5;41m"},
	Lpanic:   {"PAN", "\033[97;5;41m"},
}

Mlevel defines logging level field colorization.

Functions

func Debug

func Debug(v ...interface{})

func Debugf

func Debugf(format string, v ...interface{})

func Error

func Error(v ...interface{})

func Errorf

func Errorf(format string, v ...interface{})

func Fatal

func Fatal(v ...interface{})

func Fatalf

func Fatalf(format string, v ...interface{})

func Info

func Info(v ...interface{})

func Infof

func Infof(format string, v ...interface{})

func Level

func Level() int

func Panic

func Panic(v ...interface{})

func Panicf

func Panicf(format string, v ...interface{})

func Print

func Print(lvl int, v ...interface{})

func Printf

func Printf(lvl int, format string, v ...interface{})

func SetLevel

func SetLevel(lvl int)

func Warning

func Warning(v ...interface{})

func Warningf

func Warningf(format string, v ...interface{})

Types

type Formatter

type Formatter interface {
	Format(w io.Writer, lvl int, name string, msg string) error
	Flags() int
	SetFlags(flags int)
}

Formatter is the interface implemented by output formatters.

var DefaultFormatter Formatter

Default formatter is default output formatter. It produces colorized output if output destination is a tty and plain text otherwise. Colorization additionally can be controller by CLICOLOR and CLICOLOR_FORCE environment variables: CLICOLOR=0 disables colorization and CLICOLOR_FORCE=1 forces it even when output is not a tty.

func NewTextFormatter

func NewTextFormatter(flags int) Formatter

NextTextFormatter returns new default unstructured text formatter.

type Logger

type Logger interface {
	Print(lvl int, v ...interface{})
	Printf(lvl int, format string, v ...interface{})
	Debug(v ...interface{})
	Debugf(format string, v ...interface{})
	Info(v ...interface{})
	Infof(format string, v ...interface{})
	Warning(v ...interface{})
	Warningf(format string, v ...interface{})
	Error(v ...interface{})
	Errorf(format string, v ...interface{})
	Panic(v ...interface{})
	Panicf(format string, v ...interface{})
	Fatal(v ...interface{})
	Fatalf(format string, v ...interface{})
	Level() int
	SetLevel(lvl int)
}

Logger is the logging interface.

var Default Logger

func New

func New(name string) Logger

New returns new named os.Stdout logger with default text formatter.

func NewLogger

func NewLogger(w io.Writer, name string, f Formatter) Logger

NewLogger creates a new named logger writing to w and using formatter f.

Jump to

Keyboard shortcuts

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