diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..5566dba --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,27 @@ +on: [ push, pull_request ] +name: Test +jobs: + test: + strategy: + matrix: + os: [ ubuntu-latest, macos-latest, windows-latest ] + runs-on: ${{ matrix.os }} + steps: + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: 1.15.x + + - name: Checkout code + uses: actions/checkout@v2 + + - name: Lint slf4g + uses: golangci/golangci-lint-action@v2 + with: + version: v1.29 + + - name: Lint slf4g/native + uses: golangci/golangci-lint-action@v2 + with: + version: v1.29 + working-directory: native diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 56f8f3b..1f888de 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,9 +12,12 @@ jobs: uses: actions/setup-go@v2 with: go-version: ${{ matrix.go-version }} + - name: Checkout code uses: actions/checkout@v2 + - name: Test slf4g run: go test -v ./... + - name: Test slf4g/native run: cd native && go test -v ./... diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..e69de29 diff --git a/fields/empty.go b/fields/empty.go index 7811d3b..31cf77a 100644 --- a/fields/empty.go +++ b/fields/empty.go @@ -1,5 +1,6 @@ package fields +// Empty is returning always func Empty() Fields { return emptyV } diff --git a/fields/without.go b/fields/without.go index a7e218d..0394632 100644 --- a/fields/without.go +++ b/fields/without.go @@ -17,8 +17,11 @@ type without struct { } func (instance *without) ForEach(consumer Consumer) error { + if instance == nil { + return nil + } f := instance.fields - if instance == nil || f == nil { + if f == nil { return nil } @@ -39,8 +42,11 @@ func (instance *without) ForEach(consumer Consumer) error { } func (instance *without) Get(key string) interface{} { + if instance == nil { + return nil + } f := instance.fields - if instance == nil || f == nil { + if f == nil { return nil } diff --git a/go.mod b/go.mod index 6540fab..43390e6 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,5 @@ module github.com/echocat/slf4g go 1.13 + +require github.com/echocat/slf4g/native v0.5.3 // indirect diff --git a/logger_impl.go b/logger_impl.go index ded38a5..53591df 100644 --- a/logger_impl.go +++ b/logger_impl.go @@ -2,6 +2,7 @@ package log import ( "fmt" + "github.com/echocat/slf4g/fields" ) @@ -51,10 +52,6 @@ func (instance *loggerImpl) logf(level Level, format string, args ...interface{} instance.Log(NewEvent(level, f, 2)) } -func (instance *loggerImpl) getMessageKey() string { - return instance.GetProvider().GetFieldKeySpec().GetMessage() -} - func (instance *loggerImpl) Trace(args ...interface{}) { instance.log(LevelTrace, args...) } diff --git a/native/consumer/writer.go b/native/consumer/writer.go index 00e8362..0299b3b 100644 --- a/native/consumer/writer.go +++ b/native/consumer/writer.go @@ -2,13 +2,14 @@ package consumer import ( "fmt" + "io" + "sync" + log "github.com/echocat/slf4g" "github.com/echocat/slf4g/native/color" "github.com/echocat/slf4g/native/formatter" "github.com/echocat/slf4g/native/formatter/hints" "github.com/echocat/slf4g/native/interceptor" - "io" - "sync" ) type WritingConsumer struct { @@ -57,9 +58,7 @@ func (instance *WritingConsumer) Consume(event log.Event, source log.CoreLogger) _, _ = out.Write(content) - if canContinue := instance.onAfterLog(event, source); !canContinue { - return - } + _ = instance.onAfterLog(event, source) } func (instance *WritingConsumer) initIfRequired() { diff --git a/native/formatter/console.go b/native/formatter/console.go index 7f7a8e3..26f1760 100644 --- a/native/formatter/console.go +++ b/native/formatter/console.go @@ -2,15 +2,16 @@ package formatter import ( "bytes" + "strings" + "time" + "unicode" + "unicode/utf8" + log "github.com/echocat/slf4g" "github.com/echocat/slf4g/fields" "github.com/echocat/slf4g/native/color" "github.com/echocat/slf4g/native/formatter/hints" "github.com/echocat/slf4g/native/level" - "strings" - "time" - "unicode" - "unicode/utf8" ) var ( @@ -60,7 +61,7 @@ func (instance *Console) Format(event log.Event, using log.Provider, h hints.Hin multiLineMessage := false if message != nil { message = instance.formatMessage(message) - if strings.IndexRune(*message, '\n') >= 0 { + if strings.ContainsRune(*message, '\n') { multiLineMessage = instance.MultiLineMessageAfterFields } else { // Multiline message could be printed on a dedicated line @@ -156,15 +157,6 @@ func (instance *Console) printLevel(event log.Event, buf *bytes.Buffer, using lo return } -func (instance *Console) printMessage(event log.Event, buf *bytes.Buffer, using log.Provider, _ hints.Hints) (err error) { - if message := log.GetMessageOf(event, using); message != nil { - target := strings.TrimRightFunc(*message, unicode.IsSpace) - target = instance.ensureMessageWidth(target) - _, err = buf.WriteString(` ` + target) - } - return -} - func (instance *Console) printFields(event log.Event, buf *bytes.Buffer, using log.Provider, h hints.Hints) (printed bool, err error) { formatter := instance.getFieldValueFormatter() diff --git a/native/go.sum b/native/go.sum index 2a5be7e..26d3175 100644 --- a/native/go.sum +++ b/native/go.sum @@ -1,2 +1,3 @@ +github.com/echocat/slf4g/native v0.5.3/go.mod h1:TRok8ZG3/HTStEWhqh4GsvIx0I3tkABj9VztLtk9kkk= golang.org/x/sys v0.0.0-20200909081042-eff7692f9009 h1:W0lCpv29Hv0UaM1LXb9QlBHLNP8UFfcKjblhVCWftOM= golang.org/x/sys v0.0.0-20200909081042-eff7692f9009/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= diff --git a/native/provider.go b/native/provider.go index 86cc3ee..0b15763 100644 --- a/native/provider.go +++ b/native/provider.go @@ -2,14 +2,15 @@ package native import ( "fmt" - "github.com/echocat/slf4g" + "os" + + log "github.com/echocat/slf4g" "github.com/echocat/slf4g/fields" "github.com/echocat/slf4g/native/consumer" "github.com/echocat/slf4g/native/formatter" "github.com/echocat/slf4g/native/interceptor" "github.com/echocat/slf4g/native/level" "github.com/echocat/slf4g/native/location" - "os" ) var DefaultProvider = NewProvider("native") @@ -53,10 +54,6 @@ func (instance *Provider) GetLogger(name string) log.Logger { } func (instance *Provider) factory(name string) log.Logger { - prefix := name - if prefix == log.GlobalLoggerName { - prefix = "" - } cl := &CoreLogger{ provider: instance, name: name, @@ -80,16 +77,6 @@ func (instance *Provider) SetInterceptor(v interceptor.Interceptor) { instance.Interceptor = v } -func (instance *Provider) getInterceptor() interceptor.Interceptor { - if i := instance.GetInterceptor(); i != nil { - return i - } - if i := interceptor.Default; i != nil { - return i - } - return interceptor.Noop() -} - func (instance *Provider) GetConsumer() consumer.Consumer { return instance.Consumer } diff --git a/provider_fallback.go b/provider_fallback.go index 7d5c818..64d0951 100644 --- a/provider_fallback.go +++ b/provider_fallback.go @@ -22,10 +22,6 @@ var simpleProviderV = func() *fallbackProvider { }() func (instance *fallbackProvider) factory(name string) Logger { - prefix := name - if prefix == GlobalLoggerName { - prefix = "" - } cl := &fallbackCoreLogger{ fallbackProvider: instance, name: name,