Skip to content
Open
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
8 changes: 4 additions & 4 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ jobs:
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v2
- uses: golangci/golangci-lint-action@v2
- uses: golangci/golangci-lint-action@v7
with:
# must be specified without patch version
version: v1.46
version: v2.0.2
cross:
name: Cross
timeout-minutes: 10
strategy:
matrix:
go-version: [1.17.x]
go-version: [1.23.x]
platform: [ubuntu-latest]
runs-on: ${{ matrix.platform }}
steps:
Expand All @@ -47,7 +47,7 @@ jobs:
timeout-minutes: 10
strategy:
matrix:
go-version: [1.17.x]
go-version: [1.23.x]
platform: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.platform }}
steps:
Expand Down
39 changes: 39 additions & 0 deletions .golangci.bck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
run:
# do not run on test files yet
tests: false

# all available settings of specific linters
linters-settings:
errcheck:
# report about not checking of errors in type assetions: `a := b.(MyStruct)`;
# default is false: such cases aren't reported by default.
check-type-assertions: false

# report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`;
# default is false: such cases aren't reported by default.
check-blank: false

lll:
line-length: 100
tab-width: 4

prealloc:
simple: false
range-loops: false
for-loops: false

whitespace:
multi-if: false # Enforces newlines (or comments) after every multi-line if statement
multi-func: false # Enforces newlines (or comments) after every multi-line function signature

linters:
enable:
- megacheck
- govet
disable:
- prealloc
disable-all: false
presets:
- bugs
- unused
fast: false
95 changes: 61 additions & 34 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,40 +1,67 @@
version: "2"
run:
# do not run on test files yet
tests: false

# all available settings of specific linters
linters-settings:
errcheck:
# report about not checking of errors in type assetions: `a := b.(MyStruct)`;
# default is false: such cases aren't reported by default.
check-type-assertions: false

# report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`;
# default is false: such cases aren't reported by default.
check-blank: false

lll:
line-length: 100
tab-width: 4

prealloc:
simple: false
range-loops: false
for-loops: false

whitespace:
multi-if: false # Enforces newlines (or comments) after every multi-line if statement
multi-func: false # Enforces newlines (or comments) after every multi-line function signature

linters:
enable:
- megacheck
- govet
- asasalint
- asciicheck
- bidichk
- bodyclose
- contextcheck
- durationcheck
- errchkjson
- errorlint
- exhaustive
- gocheckcompilerdirectives
- gochecksumtype
- gosec
- gosmopolitan
- loggercheck
- makezero
- musttag
- nilerr
- nilnesserr
- noctx
- protogetter
- reassign
- recvcheck
- rowserrcheck
- spancheck
- sqlclosecheck
- testifylint
- unparam
- zerologlint
disable:
- maligned
- prealloc
disable-all: false
presets:
- bugs
- unused
fast: false
settings:
errcheck:
check-type-assertions: false
check-blank: false
lll:
line-length: 100
tab-width: 4
prealloc:
simple: false
range-loops: false
for-loops: false
whitespace:
multi-if: false
multi-func: false
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
paths:
- third_party$
- builtin$
- examples$
formatters:
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ git:
depth: 1
env:
- GO111MODULE=on
go: 1.15.x
go: 1.23.x
os: linux
install:
- ./travis/install.sh
Expand Down
2 changes: 1 addition & 1 deletion ci/go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module github.com/sirupsen/logrus/ci

go 1.15
go 1.23

require github.com/magefile/mage v1.11.0
2 changes: 1 addition & 1 deletion entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func getCaller() *runtime.Frame {
return nil
}

func (entry Entry) HasCaller() (has bool) {
func (entry *Entry) HasCaller() (has bool) {
return entry.Logger != nil &&
entry.Logger.ReportCaller &&
entry.Caller != nil
Expand Down
9 changes: 7 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
module github.com/17media/logrus

go 1.23

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/stretchr/testify v1.7.0
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8
)

go 1.13
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
)
4 changes: 2 additions & 2 deletions hooks/test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
package test

import (
"io/ioutil"
"io"
"sync"

"github.com/17media/logrus"
Expand Down Expand Up @@ -42,7 +42,7 @@ func NewLocal(logger *logrus.Logger) *Hook {
func NewNullLogger() (*logrus.Logger, *Hook) {

logger := logrus.New()
logger.Out = ioutil.Discard
logger.Out = io.Discard

return logger, NewLocal(logger)

Expand Down
18 changes: 9 additions & 9 deletions internal/testutils/testutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,33 @@ import (
"strings"
"testing"

. "github.com/17media/logrus"
"github.com/17media/logrus"

"github.com/stretchr/testify/require"
)

func LogAndAssertJSON(t *testing.T, log func(*Logger), assertions func(fields Fields)) {
func LogAndAssertJSON(t *testing.T, log func(*logrus.Logger), assertions func(fields logrus.Fields)) {
var buffer bytes.Buffer
var fields Fields
var fields logrus.Fields

logger := New()
logger := logrus.New()
logger.Out = &buffer
logger.Formatter = new(JSONFormatter)
logger.Formatter = new(logrus.JSONFormatter)

log(logger)

err := json.Unmarshal(buffer.Bytes(), &fields)
require.Nil(t, err)
require.NoError(t, err)

assertions(fields)
}

func LogAndAssertText(t *testing.T, log func(*Logger), assertions func(fields map[string]string)) {
func LogAndAssertText(t *testing.T, log func(*logrus.Logger), assertions func(fields map[string]string)) {
var buffer bytes.Buffer

logger := New()
logger := logrus.New()
logger.Out = &buffer
logger.Formatter = &TextFormatter{
logger.Formatter = &logrus.TextFormatter{
DisableColors: true,
}

Expand Down
6 changes: 3 additions & 3 deletions logrus.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type Fields map[string]interface{}
type Level uint32

// Convert the Level to a string. E.g. PanicLevel becomes "panic".
func (level Level) String() string {
func (level *Level) String() string {
if b, err := level.MarshalText(); err == nil {
return string(b)
} else {
Expand Down Expand Up @@ -56,8 +56,8 @@ func (level *Level) UnmarshalText(text []byte) error {
return nil
}

func (level Level) MarshalText() ([]byte, error) {
switch level {
func (level *Level) MarshalText() ([]byte, error) {
switch *level {
case TraceLevel:
return []byte("trace"), nil
case DebugLevel:
Expand Down
14 changes: 7 additions & 7 deletions logrus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,13 +465,13 @@ func BenchmarkWithCallerTracing(b *testing.B) {
}

func TestConvertLevelToString(t *testing.T) {
assert.Equal(t, "trace", TraceLevel.String())
assert.Equal(t, "debug", DebugLevel.String())
assert.Equal(t, "info", InfoLevel.String())
assert.Equal(t, "warning", WarnLevel.String())
assert.Equal(t, "error", ErrorLevel.String())
assert.Equal(t, "fatal", FatalLevel.String())
assert.Equal(t, "panic", PanicLevel.String())
assert.Equal(t, "trace", []Level{TraceLevel}[0].String())
assert.Equal(t, "debug", []Level{DebugLevel}[0].String())
assert.Equal(t, "info", []Level{InfoLevel}[0].String())
assert.Equal(t, "warning", []Level{WarnLevel}[0].String())
assert.Equal(t, "error", []Level{ErrorLevel}[0].String())
assert.Equal(t, "fatal", []Level{FatalLevel}[0].String())
assert.Equal(t, "panic", []Level{PanicLevel}[0].String())
}

func TestParseLevel(t *testing.T) {
Expand Down
11 changes: 6 additions & 5 deletions text_formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,11 @@ func (f *TextFormatter) needsQuoting(text string) bool {
return false
}
for _, ch := range text {
if !((ch >= 'a' && ch <= 'z') ||
(ch >= 'A' && ch <= 'Z') ||
(ch >= '0' && ch <= '9') ||
ch == '-' || ch == '.' || ch == '_' || ch == '/' || ch == '@' || ch == '^' || ch == '+') {
if (ch < 'a' || ch > 'z') &&
(ch < 'A' || ch > 'Z') &&
(ch < '0' || ch > '9') &&
ch != '-' && ch != '.' && ch != '_' && ch != '/' &&
ch != '@' && ch != '^' && ch != '+' {
return true
}
}
Expand All @@ -334,6 +335,6 @@ func (f *TextFormatter) appendValue(b *bytes.Buffer, value interface{}) {
if !f.needsQuoting(stringVal) {
b.WriteString(stringVal)
} else {
b.WriteString(fmt.Sprintf("%q", stringVal))
fmt.Fprintf(b, "%q", stringVal)
}
}
2 changes: 1 addition & 1 deletion travis/cross_build.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash

if [[ "$TRAVIS_GO_VERSION" =~ ^1\.13\. ]] && [[ "$TRAVIS_OS_NAME" == "linux" ]] && [[ "$GO111MODULE" == "on" ]]; then
if [[ "$TRAVIS_GO_VERSION" =~ ^1\.23\. ]] && [[ "$TRAVIS_OS_NAME" == "linux" ]] && [[ "$GO111MODULE" == "on" ]]; then
$(go env GOPATH)/bin/gox -build-lib
fi
6 changes: 3 additions & 3 deletions travis/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -e

# Install golanci 1.32.2
if [[ "$TRAVIS_GO_VERSION" =~ ^1\.15\. ]]; then
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b $(go env GOPATH)/bin v1.32.2
# Install golanci 2.0.2
if [[ "$TRAVIS_GO_VERSION" =~ ^1\.23\. ]]; then
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b $(go env GOPATH)/bin v2.0.2
fi
Loading