@@ -24,6 +24,7 @@ import (
2424type selectiveCore struct {
2525 allSelectors bool
2626 selectors map [string ]struct {}
27+ blockList map [string ]struct {}
2728 core zapcore.Core
2829}
2930
@@ -33,12 +34,24 @@ func HasSelector(selector string) bool {
3334 return found
3435}
3536
36- func selectiveWrapper (core zapcore.Core , selectors map [string ]struct {}) zapcore.Core {
37+ // IsBlocked returns true if the given selector was explicitly set.
38+ func IsBlocked (selector string ) bool {
39+ l := loadLogger ()
40+ _ , found := l .blockList [selector ]
41+ return found
42+ }
43+
44+ func selectiveWrapper (core zapcore.Core , selectors , blockList map [string ]struct {}) zapcore.Core {
3745 if len (selectors ) == 0 {
3846 return core
3947 }
4048 _ , allSelectors := selectors ["*" ]
41- return & selectiveCore {selectors : selectors , core : core , allSelectors : allSelectors }
49+ return & selectiveCore {
50+ selectors : selectors ,
51+ core : core ,
52+ allSelectors : allSelectors ,
53+ blockList : blockList ,
54+ }
4255}
4356
4457// Enabled returns whether a given logging level is enabled when logging a
@@ -49,7 +62,7 @@ func (c *selectiveCore) Enabled(level zapcore.Level) bool {
4962
5063// With adds structured context to the Core.
5164func (c * selectiveCore ) With (fields []zapcore.Field ) zapcore.Core {
52- return selectiveWrapper (c .core .With (fields ), c .selectors )
65+ return selectiveWrapper (c .core .With (fields ), c .selectors , c . blockList )
5366}
5467
5568// Check determines whether the supplied Entry should be logged (using the
@@ -61,6 +74,9 @@ func (c *selectiveCore) With(fields []zapcore.Field) zapcore.Core {
6174func (c * selectiveCore ) Check (ent zapcore.Entry , ce * zapcore.CheckedEntry ) * zapcore.CheckedEntry {
6275 if c .Enabled (ent .Level ) {
6376 if ent .Level == zapcore .DebugLevel {
77+ if _ , blocked := c .blockList [ent .LoggerName ]; blocked {
78+ return ce
79+ }
6480 if c .allSelectors {
6581 return ce .AddCore (ent , c )
6682 } else if _ , enabled := c .selectors [ent .LoggerName ]; enabled {
0 commit comments