@@ -408,10 +408,10 @@ def error(self, msg, *args, **kwargs):
408408 return self .log (ERROR , msg , * args , ** kwargs )
409409
410410 def warning (self , msg , * args , ** kwargs ):
411- return self .log (WARNING , msg , * args , ** kwargs )
411+ self .log (WARNING , msg , * args , ** kwargs )
412412
413413 def info (self , msg , * args , ** kwargs ):
414- return self .log (INFO , msg , * args , ** kwargs )
414+ self .log (INFO , msg , * args , ** kwargs )
415415
416416 def verbose (self , message , * args , ** kwargs ):
417417 self .log (VERBOSE , message , * args , ** kwargs )
@@ -423,6 +423,10 @@ def debug2(self, message, *args, **kwargs):
423423 self .log (DEBUG2 , message , * args , ** kwargs )
424424
425425
426+ # This is a cache for warnings that we don't want to repeat
427+ _WARN_ONCE = set ()
428+
429+
426430class LoggerAdapter (logging .LoggerAdapter ):
427431 def __init__ (self , logger = None , check = None ):
428432 super ().__init__ (
@@ -550,7 +554,13 @@ def debug2(self, message, *args, **kwargs):
550554 def verbose (self , message , * args , ** kwargs ):
551555 self .log (VERBOSE , message , * args , ** kwargs )
552556
553- def warning (self , message , * args , ** kwargs ):
557+ def warning (self , message , * args , cache = False , ** kwargs ):
558+ if cache :
559+ if message in _WARN_ONCE :
560+ return
561+
562+ _WARN_ONCE .add (message )
563+
554564 message = '%s: %s' % (sys .argv [0 ], message )
555565 if self .colorize :
556566 message = color .colorize (message , color .YELLOW )
@@ -594,6 +604,7 @@ def __init__(self, check=None, level=DEBUG):
594604 self ._orig_logger = _context_logger
595605 if check is not None :
596606 _context_logger = LoggerAdapter (_logger , check )
607+ _context_logger .colorize = self ._orig_logger .colorize
597608
598609 def __enter__ (self ):
599610 return _context_logger
0 commit comments