Skip to content

Commit

Permalink
Tweak root handlers (#554)
Browse files Browse the repository at this point in the history
  • Loading branch information
michalhabera committed Feb 2, 2023
1 parent ec10ab0 commit a55fca9
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions ffcx/codegeneration/jit.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import ffcx.naming

logger = logging.getLogger("ffcx")
root_logger = logging.getLogger()

# Get declarations directly from ufcx.h
file_dir = os.path.dirname(os.path.abspath(__file__))
Expand Down Expand Up @@ -275,6 +276,10 @@ def _compile_objects(decl, ufl_objects, object_names, module_name, options, cach

t0 = time.time()
f = io.StringIO()
# Temporarily set root logger handlers to string buffer only
# since CFFI logs into root logger
old_handlers = root_logger.handlers.copy()
root_logger.handlers = [logging.StreamHandler(f)]
with redirect_stdout(f):
ffibuilder.compile(tmpdir=cache_dir, verbose=True, debug=cffi_debug)
s = f.getvalue()
Expand All @@ -290,6 +295,10 @@ def _compile_objects(decl, ufl_objects, object_names, module_name, options, cach
fd.write(s)
fd.close()

# Copy back the original handlers (in case someone is logging into
# root logger and has custom handlers)
root_logger.handlers = old_handlers

return code_body


Expand Down

0 comments on commit a55fca9

Please sign in to comment.