Skip to content

Commit

Permalink
Added more CI and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
blaubaer committed Sep 26, 2020
1 parent b8e9615 commit cdfb57c
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 45 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ./...
Empty file added .golangci.yml
Empty file.
1 change: 1 addition & 0 deletions fields/empty.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package fields

// Empty is returning always
func Empty() Fields {
return emptyV
}
Expand Down
10 changes: 8 additions & 2 deletions fields/without.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}

Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module github.com/echocat/slf4g

go 1.13

require github.com/echocat/slf4g/native v0.5.3 // indirect
5 changes: 1 addition & 4 deletions logger_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package log

import (
"fmt"

"github.com/echocat/slf4g/fields"
)

Expand Down Expand Up @@ -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...)
}
Expand Down
9 changes: 4 additions & 5 deletions native/consumer/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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() {
Expand Down
20 changes: 6 additions & 14 deletions native/formatter/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand Down
1 change: 1 addition & 0 deletions native/go.sum
Original file line number Diff line number Diff line change
@@ -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=
19 changes: 3 additions & 16 deletions native/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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,
Expand All @@ -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
}
Expand Down
4 changes: 0 additions & 4 deletions provider_fallback.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit cdfb57c

Please sign in to comment.