Skip to content

Commit

Permalink
Style warnings to draw user attention (#978) (#984)
Browse files Browse the repository at this point in the history
* Ensure deletion of closed log handler on error

Signed-off-by: Lucas Heitzmann Gabrielli <lucas@flexcompute.com>
  • Loading branch information
lucas-flexcompute authored Jul 3, 2023
1 parent 406ff31 commit 6291b4d
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions tidy3d/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@

DEFAULT_LEVEL = "WARNING"

DEFAULT_LOG_STYLES = {
"DEBUG": None,
"INFO": None,
"WARNING": "red",
"ERROR": "red bold",
"CRITICAL": "red bold",
}


def _get_level_int(level: LogValue) -> int:
"""Get the integer corresponding to the level string."""
Expand Down Expand Up @@ -54,7 +62,13 @@ def handle(self, level, level_name, message):
if stack[offset - 1].filename.endswith("exceptions.py"):
# We want the calling site for exceptions.py
offset += 1
self.console.log(level_name, message, sep=": ", _stack_offset=offset)
self.console.log(
level_name,
message,
sep=": ",
style=DEFAULT_LOG_STYLES[level_name],
_stack_offset=offset,
)


class Logger:
Expand Down Expand Up @@ -310,8 +324,9 @@ def set_logging_file(
try:
log.handlers["file"].file.close()
except: # pylint: disable=bare-except
del log.handlers["file"]
log.warning("Log file could not be closed")
finally:
del log.handlers["file"]

try:
# pylint: disable=consider-using-with
Expand Down

0 comments on commit 6291b4d

Please sign in to comment.