semmyk commited on
Commit
51c77cb
·
1 Parent(s): 40c7aa3

fix app_logging.log if exists

Browse files
Files changed (2) hide show
  1. file_handler/file_utils.py +12 -0
  2. utils/logger.py +3 -1
file_handler/file_utils.py CHANGED
@@ -27,6 +27,18 @@ def create_outputdir(root: Union[str, Path], output_dir_string:str = None) -> Pa
27
  output_dir.mkdir(mode=0o2644, parents=True, exist_ok=True)
28
  return output_dir
29
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  def is_file_with_extension(path_obj: Path) -> bool:
31
  """
32
  Checks if a pathlib.Path object is a file and has a non-empty extension.
 
27
  output_dir.mkdir(mode=0o2644, parents=True, exist_ok=True)
28
  return output_dir
29
 
30
+ def check_create_paths(file_dir: Union[str, Path]) -> List[Path]:
31
+ """
32
+ check if File or directory path exist, else create one.
33
+ """
34
+ file_dir = Path("logs") / file_dir if not isinstance(file_dir, Path) else Path(file_dir)
35
+ if not file_dir.exists():
36
+ ##SMY: [resolved] Permission Errno13 - https://stackoverflow.com/a/57454275
37
+ file_dir.mkdir(mode=0o2644, parents=True, exist_ok=True) ##SMY: create nested path if not exists
38
+ file_dir.chmod(0)
39
+
40
+ return file_dir
41
+
42
  def is_file_with_extension(path_obj: Path) -> bool:
43
  """
44
  Checks if a pathlib.Path object is a file and has a non-empty extension.
utils/logger.py CHANGED
@@ -64,7 +64,9 @@ def setup_logging(level: int = None) -> None:
64
 
65
  # File handler
66
  #file_handler = logging.FileHandler("logs/app_logging_scrap.log", mode="a", encoding="utf-8")
67
- file_handler = logging.FileHandler("logs/app_logging.log", mode="a", encoding="utf-8")
 
 
68
  file_handler.setFormatter(JsonFormatter())
69
 
70
  root = logging.getLogger()
 
64
 
65
  # File handler
66
  #file_handler = logging.FileHandler("logs/app_logging_scrap.log", mode="a", encoding="utf-8")
67
+ #file_handler = logging.FileHandler("logs/app_logging.log", mode="a", encoding="utf-8")
68
+ from file_handler.file_utils import check_create_paths
69
+ file_handler = logging.FileHandler(check_create_paths("app_logging.log", mode="a", encoding="utf-8"))
70
  file_handler.setFormatter(JsonFormatter())
71
 
72
  root = logging.getLogger()