Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ jobs:
matrix:
go: [ "1.19", "1.20" ]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v5

- name: Set up Go
uses: actions/setup-go@v2
uses: actions/setup-go@v6
with:
go-version: ${{ matrix.go }}

Expand All @@ -30,10 +30,10 @@ jobs:
coverage:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v5

- name: Set up Go
uses: actions/setup-go@v2
uses: actions/setup-go@v6
with:
go-version: 1.19

Expand All @@ -46,10 +46,10 @@ jobs:
lint:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v5

- name: Lint
uses: golangci/golangci-lint-action@v2.5.2
uses: golangci/golangci-lint-action@v9
with:
args: "-v"
version: v1.45
version: v2.6
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v5

- name: Initialize CodeQL
uses: github/codeql-action/init@v1
Expand Down
108 changes: 79 additions & 29 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,32 +1,82 @@
issues:
exclude-rules:
# Disable some linters in tests.
- path: _test\.go
linters:
- funlen
- maligned
- gomnd
- path: adapter/internal/adaptertest
linters:
- funlen
- maligned
- gomnd

version: "2"
linters:
default: none
enable:
- asasalint
- asciicheck
- bidichk
- containedctx
- contextcheck
- cyclop
- decorder
- dogsled
- dupl
- durationcheck
- embeddedstructfieldcheck
- errcheck
- errchkjson
- errname
- errorlint
- exhaustive
- exptostd
- fatcontext
- forbidigo
- forcetypeassert
- gocheckcompilerdirectives
- gochecksumtype
- gocognit
- gocritic
- gocyclo
- gomoddirectives
- gomodguard
- goprintffuncname
- gosmopolitan
- govet
- grouper
- iface
- ineffassign
- interfacebloat
- lll
- loggercheck
- maintidx
- makezero
- mirror
- misspell
- nakedret
- nilerr
- nilnesserr
- nilnil
- noctx
- nolintlint
- perfsprint
- prealloc
- reassign
- recvcheck
- revive
- staticcheck
- tagalign
- tagliatelle
- testableexamples
- testifylint
- testpackage
- exportloopref
disable:
- interfacer
- paralleltest
- gofumpt
- exhaustivestruct
- scopelint
- gochecknoglobals
presets:
- bugs
- complexity
- format
- performance
- style
- unused
- thelper
- tparallel
- unconvert
- unparam
- unused
- usestdlibvars
- usetesting
- wastedassign
- whitespace
- wrapcheck
settings:
revive:
severity: warning
cyclop:
max-complexity: 20
nakedret:
max-func-lines: 50
lll:
line-length: 120
gocognit:
min-complexity: 64
7 changes: 3 additions & 4 deletions adapter/console/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
//
// The format of message produced by console adapters is:
//
// LEVEL message key=value key=value error=error
//
// LEVEL message key=value key=value error=error
package console

import (
Expand All @@ -21,12 +20,12 @@ import (
)

// StdoutAdapter returns a logger.Adapter implementation which prints log messages to stdout.
func StdoutAdapter() logger.Adapter { // nolint
func StdoutAdapter() logger.Adapter {
return printer.Adapter{Printer: WriterPrinter{os.Stdout}}
}

// StderrAdapter returns a logger.Adapter implementation which prints log messages to stderr.
func StderrAdapter() logger.Adapter { // nolint
func StderrAdapter() logger.Adapter {
return printer.Adapter{Printer: WriterPrinter{os.Stderr}}
}

Expand Down
8 changes: 4 additions & 4 deletions adapter/internal/adaptertest/adaptertest.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type InterfaceField struct {
}

// Run runs tests common to all logger.Adapter implementations.
func Run(t *testing.T, subject Subject) { // nolint
func Run(t *testing.T, subject Subject) { //nolint
ctx := context.Background()

var entry = logger.Entry{
Expand Down Expand Up @@ -171,7 +171,7 @@ func Run(t *testing.T, subject Subject) { // nolint
"error only": {
entry: func() logger.Entry {
e := entry
e.Error = errors.New(errorFieldValue) // nolint:goerr113
e.Error = errors.New(errorFieldValue)

return e
}(),
Expand All @@ -187,7 +187,7 @@ func Run(t *testing.T, subject Subject) { // nolint
"field and error": {
entry: func() logger.Entry {
e := entry.With(logger.Field{Key: "StringField", Value: stringFieldValue})
e.Error = errors.New(errorFieldValue) // nolint:goerr113
e.Error = errors.New(errorFieldValue)

return e
}(),
Expand All @@ -199,7 +199,7 @@ func Run(t *testing.T, subject Subject) { // nolint
e := entry.
With(logger.Field{Key: "StringField", Value: stringFieldValue}).
With(logger.Field{Key: "IntField", Value: intFieldValue})
e.Error = errors.New(errorFieldValue) // nolint:goerr113
e.Error = errors.New(errorFieldValue)

return e
}(),
Expand Down
8 changes: 4 additions & 4 deletions adapter/internal/benchmark/benchmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
var ErrSome = errors.New("ErrSome")

// Adapter runs benchmarks on any implementation of logger.Adapter.
func Adapter(b *testing.B, adapter logger.Adapter) { // nolint:funlen
func Adapter(b *testing.B, adapter logger.Adapter) { //nolint:funlen
b.Helper()

ctx := context.Background()
Expand Down Expand Up @@ -62,9 +62,9 @@ func Adapter(b *testing.B, adapter logger.Adapter) { // nolint:funlen
fields := map[string]interface{}{
"string": "str",
"int": 1,
"int64": int64(64), // nolint
"float64": 1.64, // nolint
"float32": float32(1.32), // nolint
"int64": int64(64),
"float64": 1.64,
"float32": float32(1.32),
"time": time.Time{},
}

Expand Down
5 changes: 2 additions & 3 deletions adapter/internal/fake/std.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package fake

import (
"io/ioutil"
"os"
"testing"

Expand All @@ -12,7 +11,7 @@ func swap(t *testing.T, get func() *os.File, set func(*os.File)) SwappedFile {
t.Helper()

prev := get()
tmpFile, err := ioutil.TempFile("", "")
tmpFile, err := os.CreateTemp(os.TempDir(), "")
require.NoError(t, err)

set(tmpFile)
Expand Down Expand Up @@ -40,7 +39,7 @@ func (f SwappedFile) Release() {
func (f SwappedFile) String(t *testing.T) string {
t.Helper()

line, err := ioutil.ReadFile(f.current.Name())
line, err := os.ReadFile(f.current.Name())
require.NoError(t, err)

return string(line)
Expand Down
4 changes: 2 additions & 2 deletions adapter/logadapter/logadapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/elgopher/yala/logger"
)

func Adapter(l *log.Logger) logger.Adapter { // nolint
func Adapter(l *log.Logger) logger.Adapter {
if l == nil {
return noopAdapter{}
}
Expand All @@ -21,7 +21,7 @@ type printerLogger struct {
}

func (p printerLogger) Println(skipCallerFrames int, msg string) {
_ = p.Logger.Output(skipCallerFrames+2, msg) // nolint
_ = p.Logger.Output(skipCallerFrames+2, msg) //nolint
}

type noopAdapter struct{}
Expand Down
6 changes: 1 addition & 5 deletions adapter/logfmt/logfmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,7 @@ func writeValue(builder *strings.Builder, value interface{}) {
valueStr = strings.ReplaceAll(valueStr, `"`, `\"`)
}

requiresQuoting := false

if strings.ContainsRune(valueStr, ' ') || strings.ContainsRune(valueStr, '=') {
requiresQuoting = true
}
requiresQuoting := strings.ContainsRune(valueStr, ' ') || strings.ContainsRune(valueStr, '=')

if requiresQuoting {
builder.WriteByte('"')
Expand Down
2 changes: 1 addition & 1 deletion adapter/logrusadapter/logrus.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (a Adapter) Log(ctx context.Context, entry logger.Entry) {
logrusLogger.Log(logrusLevel(entry), entry.Message)
}

func loggerWithFields(logrusLogger LogrusLogger, entry logger.Entry) LogrusLogger { // nolint:ireturn
func loggerWithFields(logrusLogger LogrusLogger, entry logger.Entry) LogrusLogger { //nolint:ireturn
length := len(entry.Fields)
if entry.Error != nil {
length++
Expand Down
2 changes: 1 addition & 1 deletion adapter/logrusadapter/logrus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestAdapter_Log(t *testing.T) {
})
}

func newAdapter(writer io.Writer) logger.Adapter { // nolint
func newAdapter(writer io.Writer) logger.Adapter {
logrusLogger := logrus.New()
logrusLogger.SetFormatter(&logrus.JSONFormatter{})
logrusLogger.SetOutput(writer)
Expand Down
2 changes: 1 addition & 1 deletion adapter/zapadapter/zapadapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestAdapter_Log(t *testing.T) {
})
}

func newAdapter(writer io.Writer) logger.Adapter { // nolint
func newAdapter(writer io.Writer) logger.Adapter {
scheme := generateUniqueScheme() // Zap does not allow to override existing scheme
_ = zap.RegisterSink(scheme, func(url *url.URL) (zap.Sink, error) {
return sinkWriter{Writer: writer}, nil
Expand Down
14 changes: 7 additions & 7 deletions logger/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import (

// Global is a logger shared globally. You can use it to define global logger for your package:
//
// package yourpackage
// import "github.com/elgopher/yala/logger"
// package yourpackage
// import "github.com/elgopher/yala/logger"
//
// var log logger.Global // define global logger, no need to initialize (by default nothing is logged)
// var log logger.Global // define global logger, no need to initialize (by default nothing is logged)
//
// func SetLoggerAdapter(adapter logger.Adapter) {
// log.SetAdapter(adapter)
// }
// func SetLoggerAdapter(adapter logger.Adapter) {
// log.SetAdapter(adapter)
// }
//
// It is safe to use it concurrently.
//
Expand Down Expand Up @@ -46,7 +46,7 @@ func (g *Global) SetAdapter(adapter Adapter) {
g.adapterValue().Store(adapterWrapper{Adapter: adapter})
}

func (g *Global) getAdapter() Adapter { // nolint:ireturn
func (g *Global) getAdapter() Adapter { //nolint:ireturn
value := g.adapterValue()

adapter, ok := value.Load().(Adapter)
Expand Down
4 changes: 2 additions & 2 deletions logger/logger_concurrency_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestConcurrency(t *testing.T) {
global.WithError(ErrSome).Error(ctx, message)
})
// then
assert.Equal(t, adapter.Count(), 6000)
assert.Equal(t, 6000, adapter.Count())
})

t.Run("normal log functions", func(t *testing.T) {
Expand All @@ -44,7 +44,7 @@ func TestConcurrency(t *testing.T) {
log.WithError(ErrSome).Error(ctx, message)
})
// then
assert.Equal(t, adapter.Count(), 6000)
assert.Equal(t, 6000, adapter.Count())
})

t.Run("With should not data race when -race flag is used", func(t *testing.T) {
Expand Down
Loading