logger

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2019 License: GPL-3.0 Imports: 6 Imported by: 39

README

go-logger

Build Status Coverage Status Go Report Card GitHub release

Lighweight wrapper for oficial Golang Log to adds support of levels for the log and reduce extra-allocations to zero.

Benchmarks

Benchmark_Printf-8       3000000               399 ns/op              67 B/op          0 allocs/op
Benchmark_Errorf-8       3000000               479 ns/op             158 B/op          0 allocs/op
Benchmark_Warningf-8     3000000               458 ns/op             160 B/op          0 allocs/op
Benchmark_Infof-8        3000000               467 ns/op             156 B/op          0 allocs/op
Benchmark_Debugf-8       3000000               459 ns/op             158 B/op          0 allocs/op

Levels:

Literal Code (constant) Value (str)
Fatal logger.FATAL fatal
Error logger.ERROR error
Warning logger.WARNING warning
Info logger.INFO info
Debug logger.DEBUG debug

The default level for std logger is logger.INFO

Output (Important)

By default, output of log is os.Stderr, but you can customize it with other io.Writer.

Format

Example of format ouput:

# Standar instance of logger
2018/03/16 12:26:48 - DEBUG - Listening on http://0.0.0.0:8000

# Own instance of logger
2018/03/16 12:26:48 - <name of instance> - DEBUG - Hello gopher

How to use:

Call logger ever you want with:

logger.Debugf("Listening on %s", "http://0.0.0.0:8000")

If you want use your own instance of logger:

myLog := logger.New("myInstance", logger.DEBUG, &bytes.Buffer{})  // Change level

myLog.Warning("Hello gopher")
Example
import bytes
import "github.com/savsgio/go-logger"


func myFunc(){
    logger.SetLevel(logger.DEBUG) // Optional (default: logger.INFO)

    ....
    logger.Infof("Hi, you are using %s/%s", "savsgio", "go-logger")
    ....

    customOutput = &bytes.Buffer{}
    myLog := logger.New("myInstance", logger.INFO, customOutput)  // Change level

    myLog.Warning("Hello gopher")
}

Contributing

Feel free to contribute it or fork me... 😉

Documentation

Index

Constants

View Source
const DEBUG = "debug"
View Source
const ERROR = "error"
View Source
const FATAL = "fatal"
View Source
const INFO = "info"
View Source
const WARNING = "warning"

Variables

This section is empty.

Functions

func Debug

func Debug(msg ...interface{})

func DebugEnabled

func DebugEnabled() bool

func Debugf

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

func Error

func Error(msg ...interface{})

func ErrorEnabled

func ErrorEnabled() bool

func Errorf

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

func Fatal

func Fatal(msg ...interface{})

func FatalEnabled

func FatalEnabled() bool

func Fatalf

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

func Info

func Info(msg ...interface{})

func InfoEnabled

func InfoEnabled() bool

func Infof

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

func Print

func Print(msg ...interface{})

func Printf

func Printf(msg string, v ...interface{})

func SetLevel

func SetLevel(level string)

func SetOutput

func SetOutput(output io.Writer)

func Warning

func Warning(msg ...interface{})

func WarningEnabled

func WarningEnabled() bool

func Warningf

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

Types

type Logger

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

func New

func New(name string, level string, output io.Writer) *Logger

New create new instance of Logger

func (*Logger) Debug

func (l *Logger) Debug(msg ...interface{})

func (*Logger) DebugEnabled

func (l *Logger) DebugEnabled() bool

func (*Logger) Debugf

func (l *Logger) Debugf(msg string, v ...interface{})

func (*Logger) Error

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

func (*Logger) ErrorEnabled

func (l *Logger) ErrorEnabled() bool

func (*Logger) Errorf

func (l *Logger) Errorf(msg string, v ...interface{})

func (*Logger) Fatal

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

func (*Logger) FatalEnabled

func (l *Logger) FatalEnabled() bool

func (*Logger) Fatalf

func (l *Logger) Fatalf(msg string, v ...interface{})

func (*Logger) Info

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

func (*Logger) InfoEnabled

func (l *Logger) InfoEnabled() bool

func (*Logger) Infof

func (l *Logger) Infof(msg string, v ...interface{})

func (*Logger) Print

func (l *Logger) Print(msg ...interface{})

func (*Logger) Printf

func (l *Logger) Printf(msg string, v ...interface{})

func (*Logger) SetLevel

func (l *Logger) SetLevel(level string)

SetLevel set level of log

func (*Logger) SetOutput

func (l *Logger) SetOutput(output io.Writer)

SetOutput set output of log

func (*Logger) Warning

func (l *Logger) Warning(msg ...interface{})

func (*Logger) WarningEnabled

func (l *Logger) WarningEnabled() bool

func (*Logger) Warningf

func (l *Logger) Warningf(msg string, v ...interface{})

Jump to

Keyboard shortcuts

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