Skip to content

Commit

Permalink
Add a dedicated function to create a logger
Browse files Browse the repository at this point in the history
  • Loading branch information
ekatef committed Oct 23, 2023
1 parent 1fc05f6 commit 821c082
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 8 additions & 5 deletions scripts/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@


def handle_exception(exc_type, exc_value, exc_traceback):
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
handler = logging.StreamHandler(stream=sys.stdout)
logger.addHandler(handler)

tb = exc_traceback
while tb.tb_next:
tb = tb.tb_next
Expand All @@ -55,6 +50,14 @@ def handle_exception(exc_type, exc_value, exc_traceback):
)


def create_logger(log_name, level=logging.INFO):
logger = logging.getLogger(log_name)
logger.setLevel(level)
handler = logging.StreamHandler(stream=sys.stdout)
logger.addHandler(handler)
sys.excepthook = handle_exception


def read_osm_config(*args):
"""
Read values from the osm_config.yaml file based on provided key arguments.
Expand Down
2 changes: 1 addition & 1 deletion scripts/build_shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
from shapely.validation import make_valid
from tqdm import tqdm

sys.excepthook = handle_exception
create_logger(__name___, level=logging.INFO)

sets_path_to_root("pypsa-earth")

Expand Down

0 comments on commit 821c082

Please sign in to comment.