Skip to content

Commit

Permalink
Merge pull request #2 from fahedouch/repo-improvement
Browse files Browse the repository at this point in the history
repo imporve
  • Loading branch information
fahedouch authored Jul 8, 2022
2 parents b7d9724 + 53bd330 commit 97617e7
Show file tree
Hide file tree
Showing 12 changed files with 383 additions and 97 deletions.
22 changes: 22 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -----------------------------------------------------------------------------
# Forked from https://raw.githubusercontent.com/opencontainers/runc/2888e6e54339e52ae45710daa9e47cdb2e1926f9/.github/dependabot.yml
# Copyright The runc Authors.
# Licensed under the Apache License, Version 2.0
# -----------------------------------------------------------------------------

# Please see the documentation for all configuration options:
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
# Dependencies listed in go.mod
- package-ecosystem: "gomod"
directory: "/" # Location of package manifests
schedule:
interval: "weekly"

# Dependencies listed in .github/workflows/*.yml
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
38 changes: 38 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: test

on:
push:
branches:
- main
- 'release/**'
pull_request:

jobs:
golangci-lint:
runs-on: ubuntu-20.04
timeout-minutes: 20
steps:
- uses: actions/[email protected]
with:
fetch-depth: 1
- uses: actions/setup-go@v3
with:
go-version: 1.18.x
- name: golangci-lint
uses: golangci/[email protected]
with:
version: v1.45.0
args: --verbose

test-unit:
runs-on: ubuntu-20.04
timeout-minutes: 20
steps:
- uses: actions/setup-go@v3
with:
go-version: 1.18.x
- uses: actions/[email protected]
with:
fetch-depth: 1
- name: "Run unit tests"
run: go test -v .
23 changes: 23 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Compiled Object files, Static and Dynamic libs (Shared Objects)
*.o
*.a
*.so

# Folders
_obj
_test

# Architecture specific extensions/prefixes
*.[568vq]
[568vq].out

*.cgo1.go
*.cgo2.c
_cgo_defun.c
_cgo_gotypes.go
_cgo_export.*

_testmain.go

*.exe
*.test
138 changes: 138 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
---
run:
concurrency: 6
deadline: 5m
linters:
disable-all: true
enable:
- deadcode
- depguard
- gofmt
- goimports
- govet
- ineffassign
- misspell
- nakedret
- prealloc
- structcheck
- typecheck
- varcheck
# - asciicheck
# - bodyclose
# - dogsled
# - dupl
# - errcheck
# - errorlint
# - exhaustive
# - exhaustivestruct
# - exportloopref
# - funlen
# - gci
# - gochecknoglobals
# - gochecknoinits
# - gocognit
# - goconst
# - gocritic
# - gocyclo
# - godot
# - godox
# - goerr113
# - gofumpt
# - goheader
# - golint
# - gomnd
# - gomodguard
# - goprintffuncname
# - gosec (gas)
- gosimple # (megacheck)
# - interfacer
# - lll
# - maligned
# - nestif
# - nlreturn
# - noctx
# - nolintlint
# - rowserrcheck
# - scopelint
# - sqlclosecheck
- staticcheck
- stylecheck
# - testpackage
# - tparallel
# - unconvert
# - unparam
# - unused
# - whitespace
# - wrapcheck
# - wsl
linters-settings:
gocritic:
enabled-checks:
# Diagnostic
- appendAssign
- argOrder
- badCond
- caseOrder
- codegenComment
- commentedOutCode
- deprecatedComment
- dupArg
- dupBranchBody
- dupCase
- dupSubExpr
- exitAfterDefer
- flagDeref
- flagName
- nilValReturn
- offBy1
- sloppyReassign
- weakCond
- octalLiteral

# Performance
- appendCombine
- equalFold
- hugeParam
- indexAlloc
- rangeExprCopy
- rangeValCopy

# Style
- assignOp
- boolExprSimplify
- captLocal
- commentFormatting
- commentedOutImport
- defaultCaseOrder
- docStub
- elseif
- emptyFallthrough
- emptyStringTest
- hexLiteral
- ifElseChain
- methodExprCall
- regexpMust
- singleCaseSwitch
- sloppyLen
- stringXbytes
- switchTrue
- typeAssertChain
- typeSwitchVar
- underef
- unlabelStmt
- unlambda
- unslice
- valSwap
- wrapperFunc
- yodaStyleExpr

# Opinionated
- builtinShadow
- importShadow
- initClause
- nestingReduce
- paramTypeCombine
- ptrToRefParam
- typeUnparen
- unnamedResult
- unnecessaryBlock
24 changes: 21 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

go-logrotate is based on [lumberjack](https://github.com/natefinch/lumberjack).

to import go-logrotate :

import "github.com/fahedouch/go-logrotate"

go-logrotate add new features to Lumberjack:
- Supporting MaxBytes to specify the log size in bytes.
- Supporting unlimited MaxBytes with `-1`.
Expand All @@ -13,16 +17,30 @@ go-logrotate add new features to Lumberjack:

## Example

To use go-logrotate with the standard library's log package, just pass it into the SetOutput function when your application starts.
To use go-logrotate with the standard library's log package and with file name standard format, just pass it into the SetOutput function when your application starts.

Code:

```
log.SetOutput(&go_logrotate.Logger{
log.SetOutput(&logrotate.Logger{
Filename: "/var/log/myapp/foo.log",
MaxBytes: 500, // bytes
MaxBackups: 3,
MaxAge: 28, //days
Compress: true, // disabled by default
})
```
```

To use go-logrotate with file name time format.
File name time format takes precedence over the standard format.

```
log.SetOutput(&logrotate.Logger{
Filename: "/var/log/myapp/foo.log",
FilenameTimeFormat: "2006-01-02T15-04-05.000",
MaxBytes: 500, // bytes
MaxBackups: 3,
MaxAge: 28, //days
Compress: true, // disabled by default
})
```
9 changes: 0 additions & 9 deletions chown.go

This file was deleted.

26 changes: 26 additions & 0 deletions examples/rotate_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//go:build linux
// +build linux

package logrotate

import (
"log"
"os"
"os/signal"
"syscall"
)

// Example of how to rotate in response to SIGHUP.
func ExampleLogger_Rotate() {
l := &Logger{}
log.SetOutput(l)
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGHUP)

go func() {
for {
<-c
l.Rotate()
}
}()
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/fahedouch/log-rotate
module github.com/fahedouch/go-logrotate

go 1.18

Expand Down
Loading

0 comments on commit 97617e7

Please sign in to comment.