Skip to content

About

Advanged Go! Log Rotation library implementation.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

15 Commits

Folders and files

Repository files navigation

glogrotation

Advanged Go! Log Rotation library implementation.

Installation

go get -u github.com/moisespsena-go/glogrotation

Usage

The Rotator struct is the concurrent io.Writer implementation.

import library:

import "github.com/moisespsena-go/glogrotation"

Rotator object

Basic:

rotator := glogrotation.New("app.log")

With custom options:

rotator := glogrotation.New("app.log", glogrotation.Options{})

Options

The Options structure:

type Options struct {
	HistoryPath  string // path inside root
	MaxSize      int64 // -1 disables limitter
	Duration     RotationDuration // Default is glogrotation.MaxSize (10M)
	FileMode     os.FileMode
	DirMode      os.FileMode
	HistoryDir   string
	HistoryCount int
}

Options.Duration field values:

  • glogrotation.Monthly or char 'M'
  • glogrotation.Weeklyor char 'W'
  • glogrotation.Dailyor char 'D'
  • glogrotation.Hourly or char 'h'
  • glogrotation.Minutely or char 'm'
  • glogrotation.Yearly or char 'Y'

Load Options From config file:

var opt glogrotation.Options
if f, err := os.Open("options.yml"); err == nil {
	var cfg glogrotation.Config
    if err = yaml.NewDecoder(f).Decode(&cfg); err != nil {
    	panic(err)
    }
    if opt, err = cfg.Options(); err != nil {
    	panic(err)
    }
} else {
	panic(err)
}

rotator := glogrotation.New("app.log", opt)

Examples

Direct write:

n, err := rotator.Write([]byte(`message\n`)) 

using io.Copy:

var r io.Reader = os.Stdin // your reader
err := io.Copy(rotator, r) 

Implementation example

See to cli source code for example.

Author

Moises P. Sena

About

Advanged Go! Log Rotation library implementation.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages

⌂ 换网址