Skip to content

Commit

Permalink
cleanup, fix setLogLevel & add tests
Browse files Browse the repository at this point in the history
* upgrade dependencies
  • Loading branch information
elv-gilles committed Feb 5, 2024
1 parent f56127a commit 5c08ea7
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 57 deletions.
17 changes: 8 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,25 @@ module github.com/eluv-io/log-go
go 1.19

require (
github.com/eluv-io/apexlog-go v1.9.1-elv3
github.com/eluv-io/errors-go v1.0.0
github.com/eluv-io/apexlog-go v1.9.1-elv3.0.20240205085428-b9e81ee49181
github.com/eluv-io/errors-go v1.0.2
github.com/eluv-io/utc-go v1.0.0
github.com/modern-go/gls v0.0.0-20220109145502-612d0167dce5
github.com/smartystreets/goconvey v1.7.2
github.com/stretchr/testify v1.7.0
gopkg.in/natefinch/lumberjack.v2 v2.0.0
github.com/smartystreets/goconvey v1.8.1
github.com/stretchr/testify v1.8.4
gopkg.in/natefinch/lumberjack.v2 v2.2.1
)

require (
github.com/BurntSushi/toml v1.0.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/eluv-io/stack v1.8.2 // indirect
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 // indirect
github.com/gopherjs/gopherjs v1.17.2 // indirect
github.com/jtolds/gls v4.20.0+incompatible // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/smartystreets/assertions v1.2.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20200605160147-a5ece683394c // indirect
github.com/smarty/assertions v1.15.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/modern-go/gls => github.com/eluv-io/gls v0.0.0-20240109172027-f54afc64be57
37 changes: 16 additions & 21 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
github.com/BurntSushi/toml v1.0.0 h1:dtDWrepsVPfW9H/4y7dDgFc2MBUSeJhlaDtK13CxFlU=
github.com/BurntSushi/toml v1.0.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/apex/log v1.9.0/go.mod h1:m82fZlWIuiWzWP04XCTXmnX0xRkYYbCdYn8jbJeLBEA=
github.com/apex/logs v1.0.0/go.mod h1:XzxuLZ5myVHDy9SAmYpamKKRNApGj54PfYLcFrXqDwo=
github.com/aphistic/golf v0.0.0-20180712155816-02c07f170c5a/go.mod h1:3NqKYiepwy8kCu4PNA+aP7WUV72eXWJeP9/r3/K9aLE=
Expand All @@ -10,11 +8,10 @@ github.com/aybabtme/rgbterm v0.0.0-20170906152045-cc83f3b3ce59/go.mod h1:q/89r3U
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/eluv-io/apexlog-go v1.9.1-elv3 h1:cWYg+5Bi5/y+R0WU3lsU3jlkNeHJv5PHXGnE1WhNPsc=
github.com/eluv-io/apexlog-go v1.9.1-elv3/go.mod h1:pZhIuRbWTsOm5WEOxke9B2dczjQuaEGeJXEYd5lCxkk=
github.com/eluv-io/errors-go v0.0.0-20220118153923-f9ef09c8c7f2/go.mod h1:bSd8y2sXPla5W9piijQn/RT00T2bC0Dce5ofvQ8vWws=
github.com/eluv-io/errors-go v1.0.0 h1:CsGhBoMWyXY1j4a4v4JiOPQrbNA7x/mm8PZCIyJJ40M=
github.com/eluv-io/errors-go v1.0.0/go.mod h1:bSd8y2sXPla5W9piijQn/RT00T2bC0Dce5ofvQ8vWws=
github.com/eluv-io/apexlog-go v1.9.1-elv3.0.20240205085428-b9e81ee49181 h1:u5dncbLB4f9PCVrC7Ba7Z9S5ojhojCaoyUIShH2ditc=
github.com/eluv-io/apexlog-go v1.9.1-elv3.0.20240205085428-b9e81ee49181/go.mod h1:pZhIuRbWTsOm5WEOxke9B2dczjQuaEGeJXEYd5lCxkk=
github.com/eluv-io/errors-go v1.0.2 h1:PcTuyv0GziUlANKSRxLAxQJwns7ZC+O3U+D1yULJJ04=
github.com/eluv-io/errors-go v1.0.2/go.mod h1:bSd8y2sXPla5W9piijQn/RT00T2bC0Dce5ofvQ8vWws=
github.com/eluv-io/gls v0.0.0-20240109172027-f54afc64be57 h1:3Xd2e2/khksl5KohJGnrLS/+rYptG/+yhjHrNvXqzQE=
github.com/eluv-io/gls v0.0.0-20240109172027-f54afc64be57/go.mod h1:4rPCrom1ZvL5sqFMGiNbCr/QfDq3oljqXEBdstdge0o=
github.com/eluv-io/stack v1.8.2 h1:yocCvAcPy9vW5iBdNnig5Tem8LgOTT8JrOLvDcacnEQ=
Expand Down Expand Up @@ -42,8 +39,8 @@ github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gopherjs/gopherjs v1.17.2 h1:fQnZVsXk8uxXIStYb0N4bGk7jeyTalG/wsZjQ25dO0g=
github.com/gopherjs/gopherjs v1.17.2/go.mod h1:pRRIvn/QzFLrKfvEz3qUuEhtE/zLCWfreZ6J5gM2i+k=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
github.com/jpillora/backoff v0.0.0-20180909062703-3050d21c67d7/go.mod h1:2iMrUgbbvHEiQClaW2NsSzMyGHqN+rDFqY705q49KG0=
Expand Down Expand Up @@ -78,19 +75,19 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/fastuuid v1.1.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
github.com/smarty/assertions v1.15.0 h1:cR//PqUBUiQRakZWqBiFFQ9wb8emQGDb0HeGdqGByCY=
github.com/smarty/assertions v1.15.0/go.mod h1:yABtdzeQs6l1brC900WlRNwj6ZR55d7B+E8C6HtKdec=
github.com/smartystreets/assertions v1.0.0/go.mod h1:kHHU4qYBaI3q23Pp3VPrmWhuIUrLW/7eUrw0BU5VaoM=
github.com/smartystreets/assertions v1.2.0 h1:42S6lae5dvLc7BrLu/0ugRtcFVjoJNMC/N3yZFZkDFs=
github.com/smartystreets/assertions v1.2.0/go.mod h1:tcbTF8ujkAEcZ8TElKY+i30BzYlVhC/LOxJk7iOWnoo=
github.com/smartystreets/go-aws-auth v0.0.0-20180515143844-0c1422d1fdb9/go.mod h1:SnhjPscd9TpLiy1LpzGSKh3bXCfxxXuqd9xmQJy3slM=
github.com/smartystreets/goconvey v1.7.2 h1:9RBaZCeXEQ3UselpuwUQHltGVXvdwm6cv1hgR6gDIPg=
github.com/smartystreets/goconvey v1.7.2/go.mod h1:Vw0tHAZW6lzCRk3xgdin6fKYcG+G3Pg9vgXWeJpQFMM=
github.com/smartystreets/goconvey v1.8.1 h1:qGjIddxOk4grTu9JPOU31tVfq3cNdBlNa5sSznIX1xY=
github.com/smartystreets/goconvey v1.8.1/go.mod h1:+/u4qLyY6x1jReYOp7GOM2FSt8aP9CzCZL03bI28W60=
github.com/smartystreets/gunit v1.0.0/go.mod h1:qwPWnhz6pn0NnRBP++URONOVyNkPyr4SauJk4cUOwJs=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/tj/assert v0.0.0-20171129193455-018094318fb0/go.mod h1:mZ9/Rh9oLWpLLDRpvE+3b7gP/C2YyLFYxNmcLnPTMe0=
github.com/tj/assert v0.0.3 h1:Df/BlaZ20mq6kuai7f5z2TvPFiwC3xaWJSDQNiIS3Rk=
github.com/tj/assert v0.0.3/go.mod h1:Ne6X72Q+TB1AteidzQncjw9PabbMp4PBMZ1k+vd1Pvk=
Expand All @@ -105,7 +102,6 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
Expand All @@ -132,7 +128,6 @@ golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand All @@ -151,15 +146,15 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXLknAOE8=
gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k=
gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc=
gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20200605160147-a5ece683394c h1:grhR+C34yXImVGp7EzNk+DTIk+323eIUWOmEevy6bDo=
gopkg.in/yaml.v3 v3.0.0-20200605160147-a5ece683394c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
15 changes: 11 additions & 4 deletions log.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,21 @@ func (l *Log) SetFatal() {
l.setLogLevel(apex.FatalLevel)
}

func (l *Log) getLogRoot() *logRoot {
return getLogRoot()
}

func (l *Log) setLogLevel(level apex.Level) {
setLevel := func(lcopy *logger) {
lcopy.logger().Level = level
setLevel := func(logCopy *logger) {
logCopy.logger().Level = level
}
getLogRoot().doLocked(func(r *logRoot) {
logName := l.get().name

root := l.getLogRoot()
root.doLocked(func(r *logRoot) {
for name, log := range r.named {
oldLogger := log.get()
if strings.HasPrefix(name, oldLogger.name) {
if strings.HasPrefix(name, logName) {
newLogger := oldLogger.copy(setLevel)
log.set(newLogger)
}
Expand Down
24 changes: 4 additions & 20 deletions log_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"sort"
"strings"
"sync"
"sync/atomic"

"gopkg.in/natefinch/lumberjack.v2"

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

var (
rootLog atomic.Pointer[logRoot]
rootLog *logRoot
)

func init() {
apex.SetHandler(json.New(os.Stdout))
rootLog.Store(defaultLogRoot())
rootLog = defaultLogRoot()
}

func defaultConfig() *Config {
Expand All @@ -37,12 +36,7 @@ func defaultConfig() *Config {
}

func defaultLogRoot() *logRoot {
defConfig := defaultConfig()
return &logRoot{
named: make(map[string]*Log),
defConfig: defConfig,
def: newLog(defConfig, defaultFields(defConfig, "/"), nil),
}
return newLogRoot(defaultConfig())
}

func newLogRoot(c *Config) *logRoot {
Expand All @@ -54,7 +48,7 @@ func newLogRoot(c *Config) *logRoot {
}

func getLogRoot() *logRoot {
return rootLog.Load()
return rootLog
}

func def() *Log {
Expand Down Expand Up @@ -317,13 +311,3 @@ func sortedKeys(m map[string]*Log) []string {
sort.Strings(keys)
return keys
}

var (
_ sync.Locker = (*noopLock)(nil)
noLock = &noopLock{}
)

type noopLock struct{}

func (n *noopLock) Lock() {}
func (n *noopLock) Unlock() {}
111 changes: 109 additions & 2 deletions log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ import (
"strings"
"sync"
"testing"
"time"

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

ljson "github.com/eluv-io/apexlog-go/handlers/json"
"github.com/eluv-io/apexlog-go/handlers/memory"
"github.com/eluv-io/log-go"
)
Expand Down Expand Up @@ -259,8 +261,8 @@ func newLogConfigDir(debug bool, dir string) *log.Config {
return c
}

func TestSetLevel(t *testing.T) {
dir, err := os.MkdirTemp(os.TempDir(), "TestSetLevel")
func TestSetLevelBasic(t *testing.T) {
dir, err := os.MkdirTemp(os.TempDir(), "TestSetLevelBasic")
require.NoError(t, err)
defer func() { _ = os.RemoveAll(dir) }()

Expand Down Expand Up @@ -300,6 +302,111 @@ func TestSetLevel(t *testing.T) {

}

// TestSetLevel test that changing the level in the hierarchy works and does not
// affect fields nor other logs located upper in the hierarchy.
func TestSetLevel(t *testing.T) {
gid := true
c := &log.Config{
Level: "info",
Handler: "json",
GoRoutineID: &gid,
Named: map[string]*log.Config{
"a": {
Level: "info",
Handler: "json",
GoRoutineID: &gid,
},
"b": {
Level: "info",
Handler: "json",
GoRoutineID: &gid,
},
},
}
log.SetDefault(c)
def := log.Root()
mh, ok := def.Handler().(*ljson.Handler)
require.True(t, ok)
// change the encoder
w := bytes.NewBuffer(make([]byte, 0))
mh.Encoder = json.NewEncoder(w)

type LogLine struct {
Fields struct {
Logger string `json:"logger"`
Gid int `json:"gid"`
} `json:"fields"`
Level string `json:"level"`
Timestamp time.Time `json:"timestamp"`
Message string `json:"message"`
}

readLogLines := func() []*LogLine {
sc := bufio.NewScanner(bytes.NewReader(w.Bytes()))
var lines []*LogLine
for sc.Scan() {
l := sc.Bytes()
logLine := &LogLine{}
err := json.Unmarshal(l, logLine)
require.NoError(t, err)
lines = append(lines, logLine)
}
return lines
}

assertLog := func(logger, level, message string) {
ll := readLogLines()
require.True(t, len(ll) > 0)
l := ll[len(ll)-1]
require.Equal(t, logger, l.Fields.Logger)
require.Equal(t, level, l.Level)
require.Equal(t, message, l.Message)
require.True(t, l.Fields.Gid > 0)
}

a := log.Get("a")
a.Info("a")
assertLog("/a", "info", "a")

b := log.Get("b")
b.Info("b")
assertLog("/b", "info", "b")

abc := log.Get("/a/b/c")
abc.Debug("abc")
assertLog("/b", "info", "b")
abc.Info("abc")
assertLog("/a/b/c", "info", "abc")

abcd := log.Get("/a/b/c/d")
abcd.Debug("abcd")
assertLog("/a/b/c", "info", "abc")
abcd.Info("abcd")
assertLog("/a/b/c/d", "info", "abcd")

abc.SetDebug()

a.Info("aa")
assertLog("/a", "info", "aa")
a.Debug("aa2")
assertLog("/a", "info", "aa")

b.Info("bb")
assertLog("/b", "info", "bb")
b.Debug("bb2")
assertLog("/b", "info", "bb")

abc.Debug("abc2")
assertLog("/a/b/c", "debug", "abc2")
abc.Info("abc3")
assertLog("/a/b/c", "info", "abc3")

abcd.Debug("abcd")
assertLog("/a/b/c/d", "debug", "abcd")
abcd.Info("abcd2")
assertLog("/a/b/c/d", "info", "abcd2")
}

// TestConcurrent is meant to be run with -race and output no race
func TestConcurrent(t *testing.T) {
dir, err := os.MkdirTemp(os.TempDir(), "TestConcurrent")
Expand Down
2 changes: 1 addition & 1 deletion logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func copyApexLogger(log apex.Interface) apex.Interface {
Handler: al.Logger.Handler,
Level: al.Logger.Level,
}
return apex.NewEntry(apx).WithFields(al.Fields)
return apex.NewEntry(apx).WithFields(al.MergedFields())
default:
panic(errors.Str(fmt.Sprintf("copyApexLogger: unknown type %v", reflect.TypeOf(log))))
}
Expand Down

0 comments on commit 5c08ea7

Please sign in to comment.