Giter Site home page Giter Site logo

revolver's Introduction

Revolver

Build Status Coverage Status Go Report Card GoDoc License

Is a simple revolving file writer for go.

Revolver allows for a simple log file rotation setup:

  • Writing dir
  • File prefix
  • File middle name
  • File suffix
  • Max file size
  • Max files

...can be customized.

Basic usage

func main() {
	w, err := revolver.NewQuick(
		"logs",
		"log_",
		".txt",
		revolver.DateStringMiddle,
		1024*1024,
		3,
	)
	if err != nil {
		panic(err)
	}
	Log := log.New(w, "", log.Ldate|log.Ltime|log.Lshortfile)
	Log.Printf("Ready to use...")
}

Alternatively must can be used to get a writer or panic:

var (
	count = 0
	w     = revolver.Must(revolver.NewQuick(
		"logs",
		"log_",
		".txt",
		revolver.DateStringMiddle,
		1024*1024,
		3,
	))
	Log = log.New(w, "", log.Ldate|log.Ltime|log.Lshortfile)
)

func main() {
	Log.Printf("Ready to use...")
}

A different use case would be:

func main() {
	count := 0
	w, err := revolver.NewQuick(
		"exports",
		"export_",
		".json",
		func() string {
			count++
			return strconv.Itoa(count)
		},
		1024*1024,
		10,
	)
	if err != nil {
		panic(err)
	}
	defer w.Close()
	w.Write([]byte("Some json data..."))
}

Parameters

Dir

Specifies the directory to write to. If the directory dose not exist, it and all parents will be created.

Prefix

The prefix is mandatory and will be used to determent which files can be deleted.

Suffix

In case the next generated filename already exists revolver will append a number to this filename. E. g. the file export.json already exists export.json_1 will be created. But now the file extension would be broken. To remedy that a filename suffix can be specified. All files are guaranteed to end with this suffix.

Middle

The middle name of the file can be customized in this function.

MaxBytes

Specifies the maximum bytes size a file can have. If the data to be written is larger then the remaining file size, a new file will be created.

MaxFiles

This is the limit of files that will be created.

Compatibility

Revolver is tested on Linux and Mac. On Windows the package seems to work. However the tests won't pass and since the returned errors are windows language specific there is no point in fixing them.

revolver's People

Contributors

jksch avatar

Stargazers

 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.