Git Product home page Git Product logo

elog's Introduction

ELOG

基于Golang的简单易用的文件日志系统。

Installation

go get -u -v github.com/zdt3476/elog

example

package main

import (
	"log"

	"github.com/zdt3476/elog"
)

func main() {
	logger, err := elog.NewELog(nil)
	if err != nil {
		log.Fatal(err)
	}
	defer logger.Close()

	logger.Debug("This is a debug msg.")
	logger.Info("This is a info msg.")
	logger.Warn("This is a warn msg.")
	logger.Error("This is a error msg.")
}

Output

[DEBG] 2017-03-31 14:24:36.559 /Users/zdt3476/Go/src/github.com/zdt3476/elog/example/basic.go:25. This is a debug msg. 
[INFO] 2017-03-31 14:24:36.559 /Users/zdt3476/Go/src/github.com/zdt3476/elog/example/basic.go:26. This is a info msg. 
[WARN] 2017-03-31 14:24:36.559 /Users/zdt3476/Go/src/github.com/zdt3476/elog/example/basic.go:27. This is a warn msg. 
[EROR] 2017-03-31 14:24:36.559 /Users/zdt3476/Go/src/github.com/zdt3476/elog/example/basic.go:28. This is a error msg.

Config

type Config struct {
	LogLevel LogLevel // 日志等级,文件和标准输出共用 default:DebugLvl

	AbsPath string // 日志文件的绝对路径

	Perm os.FileMode // 文件权限 default:0644

	EnabledStdout bool // 是否在控制台输出 default:true

	ShowLineNumber bool // 显示行号 default:true

	ShortFileName bool // 显示行号时,文件名是否包含路径 default:false

	TimeLayout string // 控制时间显示格式,default:2006-01-02 15:04:05.999
}

Rotate

推荐使用logrotate工具进行文件切分,使用Elog.Reload()方法重定向输出到新文件即可。

sig := make(chan os.Signal)
signal.Notify(sig, syscall.SIGHUP)
for s := range sig {
	if s = syscall.SIGHUP {
		if err := elog.Reload(); err != nil {
			fmt.Fprintf(os.Stderr, "Rotate log encounter a error.Error: %v", err)
		}
	}
}

elog's People

Contributors

zdt3476 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.