Skip to content

Commit

Permalink
logging fixes (#817)
Browse files Browse the repository at this point in the history
Co-authored-by: Joshua Davis <[email protected]>
  • Loading branch information
JoshSweaterGuy and Joshua Davis authored Nov 6, 2023
1 parent 5166a65 commit c841f91
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
7 changes: 5 additions & 2 deletions hammer/logging/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from functools import reduce
from enum import Enum
from typing import Callable, Iterable, List, NamedTuple, Type, Optional
import atexit

class Level(Enum):
"""
Expand Down Expand Up @@ -38,7 +39,6 @@ def with_default_callbacks(cls):
cls.add_callback(cls.callback_buffering)
return cls


class HammerVLSIFileLogger:
"""A file logger for HammerVLSILogging."""

Expand All @@ -51,6 +51,8 @@ def __init__(self, output_path: str, format_msg_callback: Optional[Callable[[Ful
"""
self._file = open(output_path, "a")
self._format_msg_callback = format_msg_callback
# close file when code exits
atexit.register(self.close)

def __enter__(self):
return self
Expand All @@ -59,7 +61,8 @@ def close(self) -> None:
"""
Close this file logger.
"""
self._file.close()
if not self._file.closed:
self._file.close()

def __exit__(self, exc_type, exc_value, traceback):
self.close()
Expand Down
3 changes: 1 addition & 2 deletions hammer/vlsi/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,11 @@ def __init__(self, options: HammerDriverOptions, extra_project_config: dict = {}
file_logger = HammerVLSIFileLogger(options.log_file)
HammerVLSILogging.add_callback(file_logger.callback)
self.log = HammerVLSILogging.context() # type: HammerVLSILoggingContext

# Create a new hammer database.
self.database = hammer_config.HammerDatabase() # type: hammer_config.HammerDatabase

self.log.info("Loading hammer-vlsi libraries and reading settings")

# Store the run dir (this should already be canonicalized by the CLI driver).
self.obj_dir = options.obj_dir # type: str

Expand Down

0 comments on commit c841f91

Please sign in to comment.