loglv

package module
v0.0.0-...-4f44f49 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2015 License: MIT Imports: 4 Imported by: 4

README

loglv

Build Status

A package supports leveled logging for Go standard log package.

Installation

Use go get command.

$ go get github.com/kohkimakimoto/loglv

Usage

package main

import (
	"log"

	"github.com/kohkimakimoto/loglv"
)

func main() {
	// At first, You should run Init method that replaces output of Go standard log package.
	loglv.Init()

	log.Println("standard log message. this is outputted!")
	// ouptput: 2015/09/09 11:18:36 standard log message. this is outputted!

	if loglv.IsDebug() {
		log.Println("debug log message. this is not outputted, because default log level is info!")
	}

	loglv.SetLv(loglv.LvDebug)
	if loglv.IsDebug() {
		log.Println("debug log message. this is outputted!")
	}
	// output: 2015/09/09 11:18:36 debug log message. this is outputted!

	loglv.SetLv(loglv.LvQuiet)
	log.Println("standard log message. but this is not outputted, because log level is quiet!")
}

Author

Kohki Makimoto kohki.makimoto@gmail.com

License

MIT license.

Documentation

Index

Constants

View Source
const (
	// LvDebug is a debug level.
	LvDebug = 4
	// LvInfo is a info level.
	LvInfo = 3
	// LvWarning is a warning level.
	LvWarning = 2
	// LvError is a error level.
	LvError = 1
	// LvQuiet is a quiet level.
	LvQuiet = 0
)

Variables

This section is empty.

Functions

func Init

func Init()

Init initializes logger output.

func IsDebug

func IsDebug() bool

IsDebug returns true value if the level is debug.

func IsError

func IsError() bool

IsError returns true value if the level is error.

func IsInfo

func IsInfo() bool

IsInfo returns true value if the level is info.

func IsQuiet

func IsQuiet() bool

IsQuiet returns true value if the level is quiet.

func IsWarning

func IsWarning() bool

IsWarning returns true value if the level is warning.

func Lv

func Lv() int

Lv returns log level

func LvString

func LvString() string

Lv returns log level string

func SetLevelByString

func SetLevelByString(lv string) error

SetLevelByString sets a log level by string.

func SetLv

func SetLv(level int)

SetLv sets log level.

func SetOutput

func SetOutput(w io.Writer)

SetOutput sets writer that is used by logging.

func Writer

func Writer() io.Writer

Writer returns a leveled log writer.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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