GitXplorerGitXplorer
x

log4g

public
0 stars
0 forks
0 issues

Commits

List of commits on branch master.
Unverified
04e22da5d2a41f71f84034cded9a1c1ebeed9b62

fix the output string

xxiaoyu830411 committed 10 years ago
Unverified
43b9c33b5de6c7a4ee671d690714d718437b9770

add a return value to RegisterAppenderType, then we can use the func in var block

xxiaoyu830411 committed 10 years ago
Unverified
bc16b14af5f34cb80fc58eb41c702e82e538c8ff

change some method to private

xxiaoyu830411 committed 10 years ago
Unverified
cd7ba9daf07c254c4d56e3e13f0115f59cce5cb9

change some method to private

xxiaoyu830411 committed 10 years ago
Unverified
0bf44511bb20c8b1378dcb210e0368fa1da715a7

update readme

xxiaoyu830411 committed 10 years ago
Unverified
dc08d548fa340f3bee724aa532b5f130dfebbdbf

update readme

xxiaoyu830411 committed 10 years ago

README

The README file for this repository.

Log

这是一个golang的log lib

#安装

go get -u github.com/xiaoyu830411/log4g/logger

快速使用

#配置文件(log4g.properties 放到项目下)

[appender]
myFile.type = file
myFile.threshold = info
myFile.path = /var/logs/my.log

[logger]
__root__ = debug, std
github.com/xiaoyu830411 = info, myFile

#代码使用

package main

import (
	"github.com/xiaoyu830411/log4g/logger"
)

var (
    log = logger.GetLog("main")
)

func main() {
    log.info("My First Log")
}

深入了解

#注册自己的Appender类型

//实现创建的接口(第一个是被创建的Appender的Id,第二个是创建的时候所需要的其他参数),请保证线程安全
//type CreateAppender func(string, map[string]string) (Appender, error)

func MyType (id string, params[string]string) (Appender, error) {
	//...
}

//实现Appender接口, 请保证线程安全
type Appender interface {
	GetId() string
	Fire(event Event)
	GetThreshold() Level
	SetThreshold(threshold Level)
}

#main 文件

package main

import (
    "github.com/xiaoyu830411/log4g/logger"
)

var (
	_ = logger.RegisterAppenderType("myType", MyType) //必须在GetLog之前
    log = logger.GetLog("main")
)

func main() {
    //....
}

#配置文件(log4g.properties 放到项目下)

[appender]
myAppender.type = myType
myAppender.threshold = info
myAppender.参数1 = 参数值1
myAppender.参数2 = 参数值2

[logger]
__root__ = debug, std
github.com/xiaoyu830411 = info, myAppender

#代码使用

package myPackage

import (
    "github.com/xiaoyu830411/log4g/logger"
)

var (
	log := logger.GetLog("github.com/xiaoyu830411/myPackage")
)

func method1() {
    log.info("I am %v", "Xiaoyu")
}