Skip to content

Commit

Permalink
implement #4595, add logx.GetLevel()
Browse files Browse the repository at this point in the history
  • Loading branch information
studyzy committed Jan 23, 2025
1 parent 4307ce4 commit 233f2bb
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions core/logc/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ func SetLevel(level uint32) {
logx.SetLevel(level)
}

// GetLevel gets the logging level.
func GetLevel() uint32 {
return logx.GetLevel()
}

// SetUp sets up the logx.
// If already set up, return nil.
// We allow SetUp to be called multiple times, because, for example,
Expand Down
2 changes: 2 additions & 0 deletions core/logc/logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ func TestMisc(t *testing.T) {
SetLevel(logx.DebugLevel)
assert.NoError(t, SetUp(LogConf{}))
assert.NoError(t, Close())
l := GetLevel()
assert.Equal(t, logx.DebugLevel, l)
}

func TestSlow(t *testing.T) {
Expand Down
5 changes: 5 additions & 0 deletions core/logx/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,11 @@ func SetLevel(level uint32) {
atomic.StoreUint32(&logLevel, level)
}

// GetLevel returns the current log level.
func GetLevel() uint32 {
return atomic.LoadUint32(&logLevel)
}

// SetWriter sets the logging writer. It can be used to customize the logging.
func SetWriter(w Writer) {
if atomic.LoadUint32(&logLevel) != disableLevel {
Expand Down
6 changes: 6 additions & 0 deletions core/logx/logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,12 @@ func TestSetLevel(t *testing.T) {
assert.Equal(t, 0, w.builder.Len())
}

func TestGetLevel(t *testing.T) {
SetLevel(ErrorLevel)
l := GetLevel()
assert.Equal(t, ErrorLevel, l)
}

func TestSetLevelTwiceWithMode(t *testing.T) {
testModes := []string{
"console",
Expand Down

0 comments on commit 233f2bb

Please sign in to comment.