golorich

package module
v0.0.0-...-0a06e48 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2018 License: MIT Imports: 6 Imported by: 0

README

golorich

Overview

Golang log standard package extension Logger

Description

  • Add a prefix of each log level to the log.
  • You can specify the log level to output. Logs less than the specified log level are not output.
    For example, error in production environment, debugging in development environment.
e.g.
logger.Debugln() // [DEBUG]
logger.Infoln() // [INFO]
logger.Warnln() // [WARN]
logger.Errorln() // [ERROR]
logger.Fatalln() // [FATAL]

Requirement

Install

go get github.com/dip-dev/golorich

Usage

logger := golorich.New(os.Stdout, "prefix_", log.LstdFlags|log.Lshortfile, golorich.Debug)
logger.Debugf("logging: %s", "debug message")
// prefix_2018/09/04 04:12:11 main.go:52: [DEBUG] logging: debug message

logger.Errorln("logging:", "error", "message")
// prefix_2018/09/04 04:12:11 main.go:53: [ERROR] logging: error message
Use environment variable for log level
logger := golorich.New(os.Stdout, "", log.LstdFlags|log.Lshortfile, golorich.GetLevelFromString(os.Getenv("LOG_LEVEL")))

Feature

  • Specifying log format
  • Specify log output destination

Licence

MIT License

Documentation

Index

Constants

View Source
const (
	Debug logutils.LogLevel = "DEBUG"
	Info  logutils.LogLevel = "INFO"
	Warn  logutils.LogLevel = "WARN"
	Error logutils.LogLevel = "ERROR"
	Fatal logutils.LogLevel = "FATAL"
)

...

Variables

This section is empty.

Functions

func GetLevelFromString

func GetLevelFromString(minLevel string) logutils.LogLevel

GetLevelFromString gets the log level from string like 'debug', 'Info', 'WARN', and so on.

Types

type Logger

type Logger struct {
	*log.Logger
}

Logger ...

func New

func New(out io.Writer, prefix string, flag int, minLevel logutils.LogLevel) *Logger

New ...

func (*Logger) Debugf

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

Debugf logs to the DEBUG log in fmt.Printf manner.

func (*Logger) Debugln

func (l *Logger) Debugln(v ...interface{})

Debugln logs to the DEBUG log in fmt.Println manner.

func (*Logger) Errorf

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

Errorf logs to the ERROR log in fmt.Printf manner.

func (*Logger) Errorln

func (l *Logger) Errorln(v ...interface{})

Errorln logs to the ERROR log in fmt.Println manner.

func (*Logger) Fatalf

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

Fatalf logs to the FATAL log in fmt.Printf manner.

func (*Logger) Fatalln

func (l *Logger) Fatalln(v ...interface{})

Fatalln logs to the FATAL log in fmt.Println manner.

func (*Logger) Infof

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

Infof logs to the INFO log in fmt.Printf manner.

func (*Logger) Infoln

func (l *Logger) Infoln(v ...interface{})

Infoln logs to the INFO log in fmt.Println manner.

func (*Logger) Warnf

func (l *Logger) Warnf(format string, v ...interface{})

Warnf logs to the WARN log in fmt.Printf manner.

func (*Logger) Warnln

func (l *Logger) Warnln(v ...interface{})

Warnln logs to the WARN log in fmt.Println manner.

Jump to

Keyboard shortcuts

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