• Stars
    star
    56
  • Rank 511,751 (Top 11 %)
  • Language
    Go
  • License
    MIT License
  • Created about 7 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Time based rotating file writer

cronowriter

GoDoc Reference CircleCI codecov Go Report Card GitHub release

This is a simple file writer that it writes message to the specified format path.

The file path is constructed based on current date and time, like cronolog.

This project follows the Semantic Versioning.

Installation

$ go get -u github.com/utahta/go-cronowriter

Documentation

API documentation can be found here.

The format specifications can be found here.

Examples

import "github.com/utahta/go-cronowriter"
w := cronowriter.MustNew("/path/to/example.log.%Y%m%d")
w.Write([]byte("test"))

// output file
// /path/to/example.log.20170204

You can specify the directory as below

w := cronowriter.MustNew("/path/to/%Y/%m/%d/example.log")
w.Write([]byte("test"))

// output file
// /path/to/2017/02/04/example.log

with Location

w := cronowriter.MustNew("/path/to/example.log.%Z", writer.WithLocation(time.UTC))
w.Write([]byte("test"))

// output file
// /path/to/example.log.UTC

with Symlink

w := cronowriter.MustNew("/path/to/example.log.%Y%m%d", writer.WithSymlink("/path/to/example.log"))
w.Write([]byte("test"))

// output file
// /path/to/example.log.20170204
// /path/to/example.log -> /path/to/example.log.20170204

with Mutex

w := cronowriter.MustNew("/path/to/example.log.%Y%m%d", writer.WithMutex())

no use Mutex

w := cronowriter.MustNew("/path/to/example.log.%Y%m%d", writer.WithNopMutex())

with Debug (stdout and stderr)

w := cronowriter.MustNew("/path/to/example.log.%Y%m%d", writer.WithDebug())
w.Write([]byte("test"))

// output file, stdout and stderr
// /path/to/example.log.20170204

with Init

w := cronowriter.MustNew("/path/to/example.log.%Y%m%d", writer.WithInit())

// open the file when New() method is called
// /path/to/example.log.20170204

Example using with zap

package main

import (
	"github.com/utahta/go-cronowriter"
	"go.uber.org/zap"
	"go.uber.org/zap/zapcore"
)

func main() {
	w1 := cronowriter.MustNew("/tmp/example.log.%Y%m%d")
	w2 := cronowriter.MustNew("/tmp/internal_error.log.%Y%m%d")
	l := zap.New(
		zapcore.NewCore(
			zapcore.NewJSONEncoder(zap.NewProductionEncoderConfig()),
			zapcore.AddSync(w1),
			zapcore.InfoLevel,
		),
		zap.ErrorOutput(zapcore.AddSync(w2)),
	)
	l.Info("test")
}

// output
// /tmp/example.log.20170204
// {"level":"info","ts":1486198722.1201255,"msg":"test"}

Contributing

  1. Fork it ( https://github.com/utahta/go-cronowriter/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

More Repositories

1

pythonbrew

Python Environment manager
Go
1,441
star
2

Flask-MVC-Pattern

mvc pattern, using flask
Python
32
star
3

vue-vuex-typescript-sandbox

TypeScript
30
star
4

WP-Social-Bookmarking-Light

Embed share buttons on your WordPress article
PHP
29
star
5

trans.nvim

Google language translator plugin for Neovim
Go
21
star
6

go-validator

Data validation library for Go
Go
17
star
7

go-openuri

Open file and url in the same interface
Go
11
star
8

go-linenotify

Go client library for LINE Notify
Go
11
star
9

flask-on-fluxflex

Flask running on fluxflex
Python
11
star
10

trans

Google Translate CLI written in Go
Go
11
star
11

swagger-doc

Easy visualize swagger.json using swagger-ui and redoc
Go
5
star
12

amazonsbr

Amazon Social Book Ranking
Python
5
star
13

node-chat

chat server. using node.js.
JavaScript
5
star
14

flask-gae-template

flask skeleton for google app engine. using buildout.
5
star
15

pyvbcode

Variable byte codes for Python
Python
5
star
16

pyahocorasick

AhoCorasick
Python
4
star
17

FastLookUp-for-Chrome

a translator extension for chrome.
JavaScript
4
star
18

go-twitter-oauth

get twitter access token with golang
Go
3
star
19

dotmoji

Get the array of pixel valid flags from font
Ruby
3
star
20

echo-sessions

Sessions middleware for Echo
Go
3
star
21

edinet_code

Get the edinet code list from EDINET
Ruby
3
star
22

grpc-go-proxy-sandbox

Go
3
star
23

momoclo-channel

Notification tool for fan of Momoiro Clover Z
Go
2
star
24

docker-wordpress-php53

Docker image for Wordpress working with PHP 5.3
Shell
2
star
25

ameblogazo

ใ‚ขใƒกใƒผใƒใƒ–ใƒญใ‚ฐใฎ็”ปๅƒใฎใƒ€ใ‚ฆใƒณใƒญใƒผใƒ‰ใ‚’็ฐกๅ˜ใซใ™ใ‚‹ใƒฉใ‚คใƒ–ใƒฉใƒช
Ruby
2
star
26

gopl

gopl memo
Go
2
star
27

jsm-gui

GUI Application. Get the japanese stock market data.
Python
2
star
28

go-twitter

๐Ÿฆ
Go
2
star
29

wp2hatena

convert images of wordpress to hatena blog
Ruby
2
star
30

cookdo

cookdo
Ruby
1
star
31

go-webapp-proto

A web application prototype built with go
1
star
32

nsync

A named mutual exclusion lock written in Go
Go
1
star
33

grpc-go-protoreflect-sandbox

Go
1
star
34

go-atomicbool

Atomic boolean for Go
Go
1
star
35

maimailog

get the maimai play log
Ruby
1
star
36

ust_notice

Ustream้…ไฟก้€š็Ÿฅ
Ruby
1
star
37

sendbuffer-overflow

send buffer overflow test
Shell
1
star
38

sakura-vps-playbook

Sakura VPS playbook
Makefile
1
star
39

simple-tcpserver

tcp server using low level api
C++
1
star
40

pagenav

Web Page Navigation
Python
1
star