mlog

package module
v0.0.0-...-259a05f Latest Latest
Warning

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

Go to latest
Published: May 4, 2016 License: Apache-2.0 Imports: 2 Imported by: 33

README

Mabetle Go Logger

Ideas from log4j.

Feathers

  • Support log level.
  • Support catalog.
  • Support appenders: Console, File, DB.
  • Support color console output.
  • Extendable, You can add new logger appender.
  • Configable, using log.conf.

Install

go get -v github.com/mabetle/mlog

Dependencies

Only depends on Go, no third part lib needed.

Usage

In Go code:
import "github.com/mabetle/mlog"

// xxx means logger catalog
var logger = mlog.GetLogger("xxx")

func init(){
	// set logger level
	mlog.SetLevel("info", "xxx")
	mlog.SetDebugLevel("xxx")
}

func XXX(){
	logger.Info("info")	
	logger.Infof("info %s", info)
}
Without configuration file, Init Logger in Go code:
func init(){
	mlog.AddAppender(...)
	mlog.SetLevel(...)
}

var logger = mlog.GetLogger("xxx")
Specific custom log config location:
mlog.LoadConfig( location )

Write Myself Appender

Appender interface define:

type Appender interface {
	// BaseAppender vars
	GetName() string

	// BaseAppender has implements these.
	SetLevel(level string, catalogs ...string)
	ScanConfigLevel(lines []string)
	IsOutputLog(level, catalog string) bool
	Inspect(catalog string)

	// each appender should implements WriteLog()
	WriteLog(level string, catalog string, callin int, msg ...interface{})
}

Your Appender implements can extends BaseAppender, BaseAppender provides all methods except WriteLog(...). You should write you own WriteLog method.

Configuration

Mlog using log.conf to config logger runtime environment.

Search log.conf in following sequence:

  • ./log.conf
  • ./conf/log.conf
  • /conf/log.conf
  • /rundata/log.conf

Logger config file format reference: misc/log_tml.conf

Known Bugs

Improvement

Welcome to help improve this library.

Report BUGS:

  • Start an issue.

Merge Request

TODO

  • Add rolling file support.

License

Apache License Version 2.0

Documentation

Overview

go logger package. ideas from java log4j. go lang provide log package, but not very configurable. Logger include some concepts: Catalog: RunLevel: Appender:

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddAppender

func AddAppender(appender logapi.Appender, lines []string)

AddAppender

func GetApiLogger

func GetApiLogger(catalog string) logapi.Logger

GetApiLogger valid wlog implements Logger API

func GetLogger

func GetLogger(catalog string) *wlog.WrapLogger

GetLogger returns wlog.WrapLogger

func GetMainLogger

func GetMainLogger() *wlog.WrapLogger

func GetWrapLogger

func GetWrapLogger(catalog string) *wlog.WrapLogger

GetWrapLogger returns wlog.WrapLogger

func LoadConfig

func LoadConfig(location string)

LoadConfig

func SetAppenderLevel

func SetAppenderLevel(appenderName, level string, catalogs ...string)

SetAppenderLevel

func SetDebugLevel

func SetDebugLevel(catalogs ...string)

func SetErrorLevel

func SetErrorLevel(catalogs ...string)

func SetInfoLevel

func SetInfoLevel(catalogs ...string)

func SetLevel

func SetLevel(level string, catalogs ...string)

Set all appenders catalogs level.

func SetTraceLevel

func SetTraceLevel(catalogs ...string)

shortcuts for set all appenders level

func SetWarnLevel

func SetWarnLevel(catalogs ...string)

Types

This section is empty.

Directories

Path Synopsis
demo
wlog wrap log, provides Info Debug ..
wlog wrap log, provides Info Debug ..

Jump to

Keyboard shortcuts

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