项目地址:https://github.com/chroblert/jgoutils/jlog
基于:https://github.com/zxysilent/logs 进行开发

使用

go get github.com/chroblert/jgoutils

package main

import (
    "github.com/chroblert/jgoutils/jlog"
    "time"
)

var(
    nlog = jlog.NewLogger(jlog.LogConfig{
        BufferSize:        2048,
        FlushInterval:     3 * time.Second,// 日志写入文件间隔
        MaxStoreDays:      -1,// 日志保存天数,-1为永久保存
        MaxSizePerLogFile: 204800000,
        LogCount:          -1,// 日志保存个数,-1为不限制
        LogFullPath:       "logs/app2.log",
        Lv:                jlog.DEBUG,
        UseConsole:        true, // 是否在控制台中显示
        Verbose:           true,
        InitCreateNewLog:  false,// 运行程序时是否新建日志文件
    })
)

func main(){
    //jlog.SetLevel(jlog.Debug)
    jlog.SetLevel(jlog.DEBUG)
    jlog.Debug("debug")
    jlog.Debugf("debug%d\n",2)
    jlog.NDebug("debug3")
    jlog.NDebugf("debug%d\n",4)
    jlog.Info("info")
    jlog.NInfo("info2")
    jlog.Warn("warn")
    jlog.NWarn("warn2")
    defer func(){
        jlog.Flush() // 在程序退出前将缓存中的日志写入文件
        nlog.Flush()
    }()
}