@@ -21,6 +21,7 @@ import (
21
21
"io"
22
22
"os"
23
23
"sync"
24
+ "sync/atomic"
24
25
"time"
25
26
26
27
"github.com/edoger/zkits-logger/internal"
@@ -184,7 +185,7 @@ type Log interface {
184
185
// and each independent Logger shares the same core instance.
185
186
type core struct {
186
187
name string
187
- level Level
188
+ level uint32
188
189
formatter Formatter
189
190
writer io.Writer
190
191
levelWriter map [Level ]io.Writer
@@ -203,7 +204,7 @@ type core struct {
203
204
func newCore (name string ) * core {
204
205
return & core {
205
206
name : name ,
206
- level : TraceLevel ,
207
+ level : uint32 ( TraceLevel ) ,
207
208
formatter : DefaultJSONFormatter (),
208
209
writer : os .Stdout ,
209
210
levelWriter : make (map [Level ]io.Writer ),
@@ -430,7 +431,7 @@ func (o *log) Log(level Level, args ...interface{}) {
430
431
431
432
// Uses the given parameters to record a log of the specified level.
432
433
func (o * log ) log (level Level , args ... interface {}) {
433
- if ! o .core .level .IsEnabled (level ) {
434
+ if ! Level ( atomic . LoadUint32 ( & o .core .level )) .IsEnabled (level ) {
434
435
return
435
436
}
436
437
o .record (level , fmt .Sprint (args ... ))
@@ -448,7 +449,7 @@ func (o *log) Logln(level Level, args ...interface{}) {
448
449
449
450
// Uses the given parameters to record a log of the specified level.
450
451
func (o * log ) logln (level Level , args ... interface {}) {
451
- if ! o .core .level .IsEnabled (level ) {
452
+ if ! Level ( atomic . LoadUint32 ( & o .core .level )) .IsEnabled (level ) {
452
453
return
453
454
}
454
455
s := fmt .Sprintln (args ... )
@@ -467,7 +468,7 @@ func (o *log) Logf(level Level, format string, args ...interface{}) {
467
468
468
469
// Uses the given parameters to record a log of the specified level.
469
470
func (o * log ) logf (level Level , format string , args ... interface {}) {
470
- if ! o .core .level .IsEnabled (level ) {
471
+ if ! Level ( atomic . LoadUint32 ( & o .core .level )) .IsEnabled (level ) {
471
472
return
472
473
}
473
474
o .record (level , fmt .Sprintf (format , args ... ))
0 commit comments