Skip to content

Commit

Permalink
feat($Loguru): log file with hostname
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnymillergh committed Aug 31, 2022
1 parent 3637b80 commit ab378b0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
4 changes: 3 additions & 1 deletion python_boilerplate/configuration/loguru_configuration.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import os
import platform
import sys

from loguru import logger
Expand All @@ -18,7 +19,8 @@
logger.remove(handler_id=None)
# Set up logging for log file
_log_file = (
f"{get_data_dir()}{os.path.sep}logs{os.path.sep}{get_module_name()}" + ".{time}.log"
f"{get_data_dir('logs')}{os.path.sep}{get_module_name()}.{platform.node()}."
+ "{time}.log"
)
log_level = application_conf.get_string("log_level")
logger.add(
Expand Down
9 changes: 7 additions & 2 deletions python_boilerplate/function_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,16 @@ def get_root_path() -> str:
return os.path.dirname(_CURRENT_FILE_PATH)


def get_data_dir() -> str:
def get_data_dir(sub_path="") -> str:
"""
Get the data directory of the project.
:param sub_path: the sub path under the `data` directory. If not exists, the sub path will be created.
"""
data_dir = f"{_PROJECT_ROOT.__str__()}{os.path.sep}data"
if len(sub_path) > 0:
data_dir = f"{_PROJECT_ROOT.__str__()}{os.path.sep}data{os.path.sep}{sub_path}"
else:
data_dir = f"{_PROJECT_ROOT.__str__()}{os.path.sep}data"
os.makedirs(data_dir, exist_ok=True)
return data_dir

Expand Down

0 comments on commit ab378b0

Please sign in to comment.