gominlog

package module
v0.0.0-...-72eebf9 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2017 License: JSON Imports: 8 Imported by: 11

README

gominlog Build Status

A minimal logger for golang with color in terminal and level.

It will also override the flag log.Lshortfile, it will give you the path of the current file which is logged without unnecessary sub folder, but for this you need to set the packageName value. this value should be the same name than your root folder project name.

Requirement

Go version: >= 1.5

Getting start

import "github.com/ArthurHlt/gominlog"

minlog := gominlog.NewClassicMinLog() // you can also use NewClassicMinLogWithPackageName("your-root-folder-name")

// it will provide a minlog with logger wrting in stdout and with flag set to log.Lshortfile | log.Ldate | log.Ltime
// You will have also color in the terminal for different level
// the log level will, by default, be set to Lall (level all)
// finally the packageName will be took from args[0] (this mean the name of your binary normally)

minlog.Debug("test debuglevel")
minlog.Error("test errorlevel")
minlog.Warning("test warninglevel")
minlog.Severe("test severelevel")
minlog.Info("test %s", "infolevel") // you can also pass values like with fmt.Sprintf

// To remove color:
minlog.WithColor(false)

// To set package Name:
minlog.SetPackageName("your-folder-name")

// To set level of logging:
minlog.SetLevel(gominlog.Lwarning) // you have alos Lall, Loff, Lsevere, Lerror, Linfo and Ldebug.

example output:

2015/11/20 18:58:57 /gominlog/gominlog_test.go:16 DEBUG: test debuglevel
2015/11/20 18:58:57 /gominlog/gominlog_test.go:17 ERROR: test errorlevel
2015/11/20 18:58:57 /gominlog/gominlog_test.go:18 SEVERE: test severelevel
2015/11/20 18:58:57 /gominlog/gominlog_test.go:19 INFO: test infolevel
2015/11/20 18:58:57 /gominlog/gominlog_test.go:21 WARNING: test warninglevel

Documentation

Index

Constants

View Source
const (
	Loff     = Level(^uint(0) >> 1)
	Lsevere  = Level(1000)
	Lerror   = Level(900)
	Lwarning = Level(800)
	Linfo    = Level(700)
	Ldebug   = Level(600)
	Lall     = Level(-Loff - 1)
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Level

type Level int

type MinLog

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

func NewClassicMinLog

func NewClassicMinLog() *MinLog

func NewClassicMinLogWithPackageName

func NewClassicMinLogWithPackageName(packageName string) *MinLog

func NewMinLog

func NewMinLog(appName string, level Level, withColor bool, flag int) *MinLog

func NewMinLogWithLogger

func NewMinLogWithLogger(packageName string, level Level, withColor bool, logger *log.Logger) *MinLog

func NewMinLogWithWriter

func NewMinLogWithWriter(appName string, level Level, withColor bool, flag int, logWriter io.Writer) *MinLog

func (*MinLog) Debug

func (this *MinLog) Debug(args ...interface{})

func (*MinLog) Error

func (this *MinLog) Error(args ...interface{})

func (*MinLog) GetLevel

func (this *MinLog) GetLevel() Level

func (*MinLog) GetLogger

func (this *MinLog) GetLogger() *log.Logger

func (*MinLog) GetPackageName

func (this *MinLog) GetPackageName() string

func (*MinLog) Info

func (this *MinLog) Info(args ...interface{})

func (*MinLog) IsColorized

func (this *MinLog) IsColorized() bool

func (*MinLog) SetLevel

func (this *MinLog) SetLevel(level Level)

func (*MinLog) SetLogger

func (this *MinLog) SetLogger(l *log.Logger)

func (*MinLog) SetPackageName

func (this *MinLog) SetPackageName(newPackageName string)

func (*MinLog) SetWriter

func (this *MinLog) SetWriter(writer io.Writer)

func (*MinLog) Severe

func (this *MinLog) Severe(args ...interface{})

func (*MinLog) Warning

func (this *MinLog) Warning(args ...interface{})

func (*MinLog) WithColor

func (this *MinLog) WithColor(isColorized bool)

Jump to

Keyboard shortcuts

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