Giter Club home page Giter Club logo

log4go's Introduction

log4go

轻量级log模块,源于google的一项log工程,官方已经停止维护更新,这里fork一份自用。

with go1.16 and support go mod

Install

go get github.com/kdpujie/log4go

example

样例代码在example文件夹下,直接运行时注意conf.yml的位置

func InitLog() {
    pwd, _ := os.Getwd()
    viper.AddConfigPath(pwd)
    viper.SetConfigType("yml")
    viper.SetConfigName("conf.yml")
    fmt.Printf("路径:%s \n", pwd)
    if err := viper.ReadInConfig(); err == nil {
        log.Println("Using config file:", viper.ConfigFileUsed())
    }
    logConfig := &log4go.LogConfig{}
    if err := viper.UnmarshalKey("log4go", logConfig); err != nil {
        log.Fatalln("[err] Unmarshal log4go config error, ", err)
    }
    if err := log4go.SetupLog(*logConfig); err != nil {
        log.Fatalln("[err] Setup log4go config, ", err)
    }
}

func main() {
    InitLog()
    log4go.Info("console Writer for log4go")
    log4go.Info("console Writer for log4go")
    log4go.Debug("console Writer for log4go")
    log4go.Error("console Writer for log4go")
    time.Sleep(2 * time.Second)
}

Features

  • 日志输出到文件,支持按日期对文件进行分割
  • 日志输出到控制台
  • 支持syslog协议.
  • 支持写入阿里云loghub

log4go's People

Contributors

xwi88 avatar

Stargazers

 avatar

Watchers

James Cloos avatar  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.