Skip to content

Commit f5597f1

Browse files
Immediately flush debug messages (#582)
1 parent 495d5a5 commit f5597f1

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

pySDC/core/controller.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,25 @@ def __setup_custom_logger(level=None, log_to_file=None, fname=None):
9292
file_handler = None
9393

9494
std_formatter = logging.Formatter(fmt='%(name)s - %(levelname)s: %(message)s')
95-
std_handler = logging.StreamHandler(sys.stdout)
95+
96+
if level <= logging.DEBUG:
97+
import warnings
98+
99+
warnings.warn('Running with debug output will degrade performance as all output is immediately flushed.')
100+
101+
class StreamFlushingHandler(logging.StreamHandler):
102+
"""
103+
This will immediately flush any messages to the output.
104+
"""
105+
106+
def emit(self, record):
107+
super().emit(record)
108+
self.flush()
109+
110+
std_handler = StreamFlushingHandler(sys.stdout)
111+
else:
112+
std_handler = logging.StreamHandler(sys.stdout)
113+
96114
std_handler.setFormatter(std_formatter)
97115

98116
# instantiate logger

0 commit comments

Comments
 (0)