@@ -3214,6 +3214,37 @@ def format(self, record):
32143214 }
32153215 }
32163216
3217+ # Remove when deprecation ends.
3218+ class DeprecatedStrmHandler (logging .StreamHandler ):
3219+ def __init__ (self , strm = None ):
3220+ super ().__init__ (stream = strm )
3221+
3222+ config_custom_handler_with_deprecated_strm_arg = {
3223+ 'version' : 1 ,
3224+ 'formatters' : {
3225+ 'form1' : {
3226+ 'format' : '%(levelname)s ++ %(message)s' ,
3227+ },
3228+ },
3229+ 'handlers' : {
3230+ 'hand1' : {
3231+ 'class' : DeprecatedStrmHandler ,
3232+ 'formatter' : 'form1' ,
3233+ 'level' : 'NOTSET' ,
3234+ 'stream' : 'ext://sys.stdout' ,
3235+ },
3236+ },
3237+ 'loggers' : {
3238+ 'compiler.parser' : {
3239+ 'level' : 'DEBUG' ,
3240+ 'handlers' : ['hand1' ],
3241+ },
3242+ },
3243+ 'root' : {
3244+ 'level' : 'WARNING' ,
3245+ },
3246+ }
3247+
32173248 def apply_config (self , conf ):
32183249 logging .config .dictConfig (conf )
32193250
@@ -3303,6 +3334,15 @@ def test_config5_ok(self):
33033334 self .test_config1_ok (config = self .config5 )
33043335 self .check_handler ('hand1' , CustomHandler )
33053336
3337+ def test_deprecation_warning_custom_handler_with_strm_arg (self ):
3338+ msg = (
3339+ "Support for custom logging handlers with the 'strm' argument "
3340+ "is deprecated and scheduled for removal in Python 3.15. "
3341+ "Define handlers with the 'stream' argument instead."
3342+ )
3343+ with self .assertWarnsRegex (DeprecationWarning , msg ):
3344+ self .test_config1_ok (config = self .config_custom_handler_with_deprecated_strm_arg )
3345+
33063346 def test_config6_failure (self ):
33073347 self .assertRaises (Exception , self .apply_config , self .config6 )
33083348
0 commit comments