[go: up one dir, main page]

logger

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2018 License: BSD-3-Clause Imports: 5 Imported by: 0

README

Simple level logging package.

package main

import (
	"log"
	"os"
	"runtime"

	"github.com/chai2010/logger"
)

func init() {
	logger.SetLogger(logger.NewStdLogger(os.Stderr, "", "", log.Lshortfile))
}

func main() {
	var logger = logger.GetLogger()

	logger.SetLevel("DEBUG")
	logger.Debug(runtime.Version())
	logger.Info("hello")
}

Output:

hello.go:25: [DEBUG] go1.10
hello.go:26: [INFO] hello

Documentation

Overview

Example
package main

import (
	"github.com/chai2010/logger"
)

func main() {
	var logger = logger.GetLogger()

	logger.SetLevel("DEBUG")
	logger.Debug("1+1=2")
	logger.Info("hello")
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Logger

type Logger interface {
	Debug(v ...interface{})
	Debugln(v ...interface{})
	Debugf(format string, v ...interface{})
	Info(v ...interface{})
	Infoln(v ...interface{})
	Infof(format string, v ...interface{})
	Warning(v ...interface{})
	Warningln(v ...interface{})
	Warningf(format string, v ...interface{})
	Error(v ...interface{})
	Errorln(v ...interface{})
	Errorf(format string, v ...interface{})
	Panic(v ...interface{})
	Panicln(v ...interface{})
	Panicf(format string, v ...interface{})
	Fatal(v ...interface{})
	Fatalln(v ...interface{})
	Fatalf(format string, v ...interface{})

	// Level: DEBUG < INFO < WARN < ERROR < PANIC < FATAL
	GetLevel() string
	SetLevel(new string) (old string)
}

Logger interface

See https://github.com/chai2010/logger

func GetLogger

func GetLogger() Logger

func NewStdLogger

func NewStdLogger(out io.Writer, prefix, level string, flag int) Logger

NewStdLogger create new logger based on std log. If level is empty string, use WARN as the default level. If flag is zore, use 'log.LstdFlags|log.Lshortfile' as the default flag. Level: DEBUG < INFO < WARN < ERROR < PANIC < FATAL

Example
package main

import (
	"log"
	"os"

	"github.com/chai2010/logger"
)

func main() {
	var logger = logger.NewStdLogger(os.Stderr, "", "", log.Lshortfile)

	logger.Debug("1+1=2")
	logger.Info("hello")
}
Output:

func SetLogger

func SetLogger(new Logger) (old Logger)

Jump to

Keyboard shortcuts

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