logger

package module
v0.0.0-...-e3f38a9 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2015 License: BSD-3-Clause Imports: 7 Imported by: 0

README

Logger

build status

logger framework

Installation

go get github.com/hgoo/logger

Usage

package main
import (
	"github.com/hgoo/logger"
)
func main() {
	log := logger.Get("main").Register(logger.ConsoleLogger())// Default Use ConsoleLogger
	//	log.Register(logger.FileLogger())
	log.D("Debug %d", 1)
	//or
	logger.Get("main").V("Verbose %d", 2)
	logger.Get("main").W("Warning %d", 3)
	hgoo.Run()
}

Advanced usage

package main
import (
	"github.com/hgoo/logger"
)
func main() {
	config := logger.ConsoleConfig{DataFormat:time.Kitchen}//Specify time format
	writer := logger.ConsoleWriter{}
	adapter := logger.LogAdapter{&config, &writer}
	log:=logger.Get("main").Register(adapter)
	log.D("Debug %d", 1)
	//or
	logger.Get("main").V("Verbose %d", 2)
	logger.Get("main").W("Warning %d", 3)
	hgoo.Run()
}

Or

//Implement interface
type LogWriter interface {
	Init(name string, config config []byte)
	Verbose(format string, args ...interface{})
	Debug(format string, args ...interface{})
	Info(format string, args ...interface{})
	Warn(format string, args ...interface{})
	Error(format string, err error, args ...interface{})
}
//Implement interface
type LogConfig interface {
	toJson() []byte
}
......
......
func (config *ConsoleConfig)toJson() []byte {
	if config.DataFormat == "" {
		config.DataFormat = "2006-01-02 15:04:05"
	}
	if JSON, err := json.Marshal(config); err == nil {
		return JSON
	}
	return nil;
}
......
......
func (this *ConsoleWriter)Init(name string, config config []byte) {
	this.name = name;
	err := json.Unmarshal(config, &this.config)
	if err != nil {
		panic(err)
	}
}

License

See LICENSE.

Documentation

Index

Constants

View Source
const (
	VERBOSE = iota
	DEBUG   = iota
	INFO    = iota
	WARN    = iota
	ERROR   = iota
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ConsoleConfig

type ConsoleConfig struct {
	DateFormat string
}

type ConsoleWriter

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

func (*ConsoleWriter) Debug

func (this *ConsoleWriter) Debug(format string, args ...interface{})

func (*ConsoleWriter) Error

func (this *ConsoleWriter) Error(format string, err error, args ...interface{})

func (*ConsoleWriter) Info

func (this *ConsoleWriter) Info(format string, args ...interface{})

func (*ConsoleWriter) Init

func (this *ConsoleWriter) Init(name string, config []byte)

func (*ConsoleWriter) Verbose

func (this *ConsoleWriter) Verbose(format string, args ...interface{})

func (*ConsoleWriter) Warn

func (this *ConsoleWriter) Warn(format string, args ...interface{})

type FileConfig

type FileConfig struct {
	Dir        string
	DateFormat string
}

type FileWriter

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

func (*FileWriter) Debug

func (this *FileWriter) Debug(format string, args ...interface{})

func (*FileWriter) Error

func (this *FileWriter) Error(format string, err error, args ...interface{})

func (*FileWriter) Info

func (this *FileWriter) Info(format string, args ...interface{})

func (*FileWriter) Init

func (this *FileWriter) Init(name string, config []byte)

func (*FileWriter) Printf

func (this *FileWriter) Printf()

func (*FileWriter) Verbose

func (this *FileWriter) Verbose(format string, args ...interface{})

func (*FileWriter) Warn

func (this *FileWriter) Warn(format string, args ...interface{})

type LogAdapter

type LogAdapter struct {
	Config LogConfig
	Writer LogWriter
}

func ConsoleLogger

func ConsoleLogger() *LogAdapter

func FileLogger

func FileLogger() *LogAdapter

type LogConfig

type LogConfig interface {
	// contains filtered or unexported methods
}

type LogWriter

type LogWriter interface {
	Init(name string, config []byte)
	Verbose(format string, args ...interface{})
	Debug(format string, args ...interface{})
	Info(format string, args ...interface{})
	Warn(format string, args ...interface{})
	Error(format string, err error, args ...interface{})
}

type Logger

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

func Get

func Get(logName string) *Logger

func (*Logger) D

func (l *Logger) D(format string, args ...interface{})

func (*Logger) E

func (l *Logger) E(format string, err error, args ...interface{})

func (*Logger) I

func (l *Logger) I(format string, args ...interface{})

func (*Logger) Register

func (l *Logger) Register(adapter *LogAdapter) *Logger

func (*Logger) V

func (l *Logger) V(format string, args ...interface{})

func (*Logger) W

func (l *Logger) W(format string, args ...interface{})

Directories

Path Synopsis
Godeps
_workspace/src/github.com/issue9/term/colors
colors 带色彩的控制台文本输出包,兼容windows平台。
colors 带色彩的控制台文本输出包,兼容windows平台。

Jump to

Keyboard shortcuts

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