GithubHelp home page GithubHelp logo

logcuting's Introduction

Logcuting

文件日志切割库,返回一个满足io.Writer和io.Close接口的实例。

功能

  • 按时间间隔切割日志文件
  • 按日志文件大小切割日志文件
  • 配置信息更新

日志文件切割优先级

  • 文件大小
  • 时间间隔

配置信息说明

  • Name 日志文件目录,需要带时间格式。例如:./log/demo-%Y%m%d%H%M%S.log
  • Time 日志切割时间间隔,0每天凌晨切割,最小切割间隙1分钟。例如:time.Minute
  • Size 日志文件切割大小,单位MB。例如:5

导入Logcuting

go get -u github.com/lgyong511/logcuting

使用Logcuting

package main

import (
	"time"

	"github.com/lgyong511/logcuting"
	"github.com/sirupsen/logrus"
)

func main() {
	// 设置日志级别
	logrus.SetLevel(logrus.DebugLevel)
	// 设置日志输出格式
	logrus.SetFormatter(&logrus.JSONFormatter{})
	// 设置输出文件名行号函数名
	logrus.SetReportCaller(true)

	// 创建logcuting实例
	logcut := logcuting.NewLogcuting(&logcuting.Config{
		Name: "./log/demo-%Y%m%d%H%M.log",
		Time: time.Minute,
		// Size: 1,
	})
	
	// 将logcut作为logrus的输出目标
	logrus.SetOutput(logcut)
	logrus.Info("将日志输出到logcut")

logcuting's People

Contributors

lgyong511 avatar

Watchers

 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.