@@ -73,11 +73,10 @@ def is_debug_set(logger):
7373 """
7474 if logger .manager .disable >= _DEBUG :
7575 return False
76- _level = logger .getEffectiveLevel ()
7776 # Filter out NOTSET and higher levels
78- return _NOTSET < _level <= _DEBUG
77+ return _NOTSET < logger . getEffectiveLevel () <= _DEBUG
7978
80- else :
79+ elif sys . version_info [: 3 ] < ( 3 , 13 , 4 ) :
8180 # This is inefficient (it indirectly checks effective level twice),
8281 # but is included for [as yet unknown] platforms that ONLY implement
8382 # the API documented in the logging library
@@ -86,6 +85,15 @@ def is_debug_set(logger):
8685 return False
8786 return logger .getEffectiveLevel () > _NOTSET
8887
88+ else :
89+ # Python 3.14 (and backported to python 3.13.4) changed the behavior
90+ # of isEnabledFor() so that it always returns False when called
91+ # while a log record is in flight (learned this from
92+ # https://github.com/hynek/structlog/pull/723). In newer versions
93+ # of Python, we will only rely on getEffectiveLevel().
94+ def is_debug_set (logger ):
95+ return _NOTSET < logger .getEffectiveLevel () <= _DEBUG
96+
8997
9098class WrappingFormatter (logging .Formatter ):
9199 _flag = "<<!MSG!>>"
@@ -262,7 +270,7 @@ def filter(self, record):
262270pyomo_logger = logging .getLogger ('pyomo' )
263271pyomo_handler = logging .StreamHandler (sys .stdout )
264272pyomo_formatter = LegacyPyomoFormatter (
265- base = PYOMO_ROOT_DIR , verbosity = lambda : pyomo_logger . isEnabledFor ( logging . DEBUG )
273+ base = PYOMO_ROOT_DIR , verbosity = lambda : is_debug_set ( pyomo_logger )
266274)
267275pyomo_handler .setFormatter (pyomo_formatter )
268276pyomo_handler .addFilter (_GlobalLogFilter ())
@@ -469,7 +477,7 @@ def __enter__(self):
469477 # #3587), so we will just handle it explicitly ourselves.
470478 self .local_fd = os .dup (self .fd )
471479 self .handler .stream = os .fdopen (
472- self .local_fd , mode = "a " , closefd = False
480+ self .local_fd , mode = "w " , closefd = False
473481 ).__enter__ ()
474482
475483 def __exit__ (self , et , ev , tb ):
@@ -495,7 +503,7 @@ def __enter__(self):
495503 # #3587), so we will just handle it explicitly ourselves.
496504 self .local_fd = os .dup (self .fd )
497505 logging .lastResort = logging .StreamHandler (
498- os .fdopen (self .local_fd , mode = "a " , closefd = False ).__enter__ ()
506+ os .fdopen (self .local_fd , mode = "w " , closefd = False ).__enter__ ()
499507 )
500508
501509 def __exit__ (self , et , ev , tb ):
0 commit comments