diff --git a/.travis.yml b/.travis.yml index c6207d2..0b382e1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,14 @@ language: go -sudo: false -go: - - "1.14" - - tip +go_import_path: github.com/iproj/file-rotatelogs +os : linux +jobs: + include: + - stage: build + os: linux + go: 1.14 + env: GO111MODULE=on + script: + - go test + after_success: + - bash <(curl -s https://codecov.io/bash) + diff --git a/README.md b/README.md index 8781dc1..a1971ae 100644 --- a/README.md +++ b/README.md @@ -3,14 +3,16 @@ file-rotatelogs Provide an `io.Writer` that periodically rotates log files from within the application. Port of [File::RotateLogs](https://metacpan.org/release/File-RotateLogs) from Perl to Go. -[![Build Status](https://travis-ci.org/lestrrat-go/file-rotatelogs.png?branch=master)](https://travis-ci.org/lestrrat-go/file-rotatelogs) - -[![GoDoc](https://godoc.org/github.com/lestrrat-go/file-rotatelogs?status.svg)](https://godoc.org/github.com/lestrrat-go/file-rotatelogs) - -# WARNINGS - -THIS PROJECT HAS BEEN ARCHIVED. IT WILL NOT RECEIVE UPDATES, THE AUTHOR DOES NOT WISH TO MAINTAIN OR SUPPORT IT. -IN SHORT, DO NOT USE THIS PROJECT. +[![version](https://img.shields.io/github/v/tag/iproj/file-rotatelogs.svg?sort=semver)](https://github.com/iproj/file-rotatelogs/releases/latest) +[![API Reference](https://camo.githubusercontent.com/915b7be44ada53c290eb157634330494ebe3e30a/68747470733a2f2f676f646f632e6f72672f6769746875622e636f6d2f676f6c616e672f6764646f3f7374617475732e737667)](https://godoc.org/github.com/iproj/file-rotatelogs) +[![Go version](https://img.shields.io/badge/go-1.14-blue.svg)](https://github.com/moovweb/gvm) +[![Go Report Card](https://goreportcard.com/badge/github.com/iproj/file-rotatelogs)](https://goreportcard.com/report/github.com/iproj/file-rotatelogs) +[![Travis](https://travis-ci.com/iproj/file-rotatelogs.svg?branch=main)](https://travis-ci.com/iproj/file-rotatelogs) +[![license](https://img.shields.io/github/license/iproj/file-rotatelogs.svg)](https://github.com/iproj/file-rotatelogs/blob/main/LICENSE) + +| Branch | Tests | Coverage | +| ------ | ---------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ | +| main | [![TravisCI](https://travis-ci.com/iproj/file-rotatelogs.svg?branch=main)](https://travis-ci.com/iproj/file-rotatelogs) | [![codecov](https://codecov.io/gh/iproj/file-rotatelogs/branch/main/graph/badge.svg)](https://codecov.io/gh/iproj/file-rotatelogs) | # SYNOPSIS diff --git a/example_test.go b/example_test.go index 06b4170..5412c76 100644 --- a/example_test.go +++ b/example_test.go @@ -3,9 +3,14 @@ package rotatelogs_test import ( "fmt" "io/ioutil" + "log" "os" + "path/filepath" + "strconv" + "testing" rotatelogs "github.com/iproj/file-rotatelogs" + "github.com/stretchr/testify/assert" ) func ExampleForceNewFile() { @@ -61,3 +66,37 @@ func ExampleForceNewFile() { // test.log 4 // test.log.1 4 } + +func TestTooMuchLog(t *testing.T) { + + var ( + testDir = "test_much_log" + testLogPath = filepath.Join(testDir, "access_log") + rotationCount = 3 + N = 12 // N < log.Printf content size + ) + err := os.Mkdir(testDir, 0777) + assert.Nil(t, err) + defer os.RemoveAll(testDir) + assert.Nil(t, err) + + rl, err := rotatelogs.New( + testLogPath+".%Y%m%d%H%M", + rotatelogs.WithLinkName(testLogPath), + rotatelogs.WithRotationCount(uint(rotationCount)), + rotatelogs.WithRotationSize(12), + ) + assert.Nil(t, err) + + log.SetOutput(rl) + for i := 0; i < N; i++ { + log.Printf("Test content %d\n", i) + } + files, _ := ioutil.ReadDir(testDir) + fmt.Println(files) + assert.Equal(t, rotationCount+1, len(files)) + + bytez, err := ioutil.ReadFile(testLogPath) + assert.Nil(t, err) + assert.Equal(t, strconv.Itoa(N-1), string(bytez[len(bytez)-3:len(bytez)-1])) +} diff --git a/go.mod b/go.mod index 44ce88b..cb75be5 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/lestrrat-go/file-rotatelogs +module github.com/iproj/file-rotatelogs go 1.12