Coder Social home page Coder Social logo

filehook's Introduction

File Hook

File hook for logrus

Usage

package main

import (
	log "github.com/sirupsen/logrus"
	"github.com/wangxianzhuo/filehook"
)

func main() {
	// use default path(./log)
	hook, err := filehook.New(&filehook.Option{
		Path:            "./logs/",
		SegmentInterval: 86400,
		NamePattern:     "%YY-%MM-%DD_%HH-%mm-%SS.log",
		LineBreak:       "\n",
	})
	if err != nil {
		panic(err)
	}
	log.AddHook(hook)

	log.Infof("info1")
	log.Infof("info2")
	// time.Sleep(15 * time.Second)
	log.Warnf("warn1")
	log.Warnf("warn2")
}

Parameter

Option

  • Path the logs store path
    • type string
    • default default ./logs/
  • LineBreak the line break
    • type string
    • value \n or \r\n
    • default default \n
  • SegmentInterval segment file interval, unit second
    • type int64
    • value -1 is no segmention, 0 default segmention, >0 segmention interval
    • default default 86400
  • namePattern is the log file name pattern. It can only use SetFileNamePattern() to modify.
    • type string
    • default %YY-%MM-%DD_%HH-%mm-%SS.log

Installation

go get -u github.com/wangxianzhuo/filehook

filehook's People

Contributors

wangxianzhuo avatar

Watchers

James Cloos avatar  avatar

filehook's Issues

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.