log

package
v0.10.4 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2020 License: MIT Imports: 8 Imported by: 0

README

Logger Proxy API

Consts (in decreasing order of severity):

  • FATAL
  • ERROR
  • WARN
  • INFO
  • DEBUG
  • TRACE

Functions:

  • log.SetLogLevel(): Log messages below this level of severity will be ignored. Default Log Level is INFO.

  • Each of the following also has a formatting string variety; i.e. Fatalf(), Errorf(), etc which behaves the same as fmt.Printf() but outputs to the log instead of stdout.

  • log.Fatal(vals... interface{}): prevents the program from continuing i.e. can't allocate additional memory

  • log.Error(vals... interface{}): non-fatal, but prevents valid execution i.e. can't connect to a database, complete a function call, open file, invalid format

  • log.Warn(vals... interface{}): looks unusual, but does not clearly prevent execution

  • log.Info(vals... interface{}): Least severe message that a sysadmin would be interested in i.e. server request logs

  • log.Debug(vals... interface{}): high level info for a developer. more than what a sysadmin would typically want

  • log.Trace(vals... interface{}): excruciating detail.

  • log.SetOutput(io.Writer): Indicates the location for log messages to be written. Default is stdout.

Flags:

These package-level flags are provided to disable expensive code when the code is only needed at
a lower severity than the logger is set at:
    IsError
    IsWarn
    IsInfo
    IsDebug
    IsTrace

example usage:
     if log.IsDebug {
         ...
     }

Output will look like:

"timestamp•LOG_LEVEL•filename.go•linenumber•output"

Documentation

Index

Constants

View Source
const (
	TRACE = Level(iota - 2)
	DEBUG
	INFO
	WARN
	ERROR
	FATAL
)

Allows the ordering of severity to be checked

View Source
const CallerSkipLevel = 3

CallerSkipLevel is the number of levels to skip https://godoc.org/runtime#Caller

Variables

View Source
var (

	// FATAL level is never disabled
	IsError bool
	IsWarn  bool
	IsInfo  bool
	IsDebug bool
	IsTrace bool
)
View Source
var TimestampRegex string = `\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}` // Ex: "2006-01-02 15:04:05"

Functions

func Debug

func Debug(args ...interface{})

func Debugf added in v0.6.0

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

func Error

func Error(args ...interface{})

func Errorf added in v0.6.0

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

func Fatal

func Fatal(args ...interface{})

func Fatalf added in v0.6.0

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

Output format should be: "timestamp•LOG_LEVEL•filename.go•linenumber•output"

func Info

func Info(args ...interface{})

func Infof added in v0.6.0

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

func SetLogLevel

func SetLogLevel(lvl Level)

func SetOutput

func SetOutput(w io.Writer)

func StdErrOutput added in v0.8.0

func StdErrOutput(level string, args ...interface{})

func StdOutOutput added in v0.8.0

func StdOutOutput(level string, args ...interface{})

func Trace

func Trace(args ...interface{})

func Tracef added in v0.6.0

func Tracef(format string, args ...interface{})

func Warn

func Warn(args ...interface{})

func Warnf added in v0.6.0

func Warnf(format string, args ...interface{})

Types

type Interface

type Interface interface {
	// These all take args the same as calls to fmt.Printf()
	Fatal(...interface{})
	Error(...interface{})
	Warn(...interface{})
	Info(...interface{})
	Debug(...interface{})
	Trace(...interface{})
	SetOutput(io.Writer)
}

type Level

type Level int

func (Level) String added in v0.9.0

func (lvl Level) String() string

type Standard

type Standard struct{}

func (Standard) Debug

func (_ Standard) Debug(args ...interface{})

func (Standard) Error

func (_ Standard) Error(args ...interface{})

func (Standard) Fatal

func (_ Standard) Fatal(args ...interface{})

func (Standard) Info

func (_ Standard) Info(args ...interface{})

func (Standard) SetOutput

func (_ Standard) SetOutput(w io.Writer)

func (Standard) Trace

func (_ Standard) Trace(args ...interface{})

func (Standard) Warn

func (_ Standard) Warn(args ...interface{})

Jump to

Keyboard shortcuts

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