-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ab1190d
commit 8b848dd
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import sys | ||
|
||
|
||
def error_message_detail(error, error_detail: sys): | ||
_, _, exc_tb = error_detail.exc_info() | ||
|
||
file_name = exc_tb.tb_frame.f_code.co_filename | ||
|
||
error_message = "Error occurred python script name [{0}] line number [{1}] error message [{2}]".format( | ||
file_name, exc_tb.tb_lineno, str(error) | ||
) | ||
|
||
return error_message | ||
|
||
|
||
class CustomException(Exception): | ||
def __init__(self, error_message, error_detail): | ||
""" | ||
:param error_message: error message in string format | ||
""" | ||
super().__init__(error_message) | ||
|
||
self.error_message = error_message_detail( | ||
error_message, error_detail=error_detail | ||
) | ||
|
||
def __str__(self): | ||
return self.error_message | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import logging | ||
import os | ||
from datetime import datetime | ||
from from_root import from_root | ||
|
||
|
||
LOG_FILE = f"{datetime.now().strftime('%m_%d_%Y_%H_%M_%S')}.log" | ||
|
||
log_path = os.path.join(from_root(), 'log', LOG_FILE) | ||
|
||
os.makedirs(log_path, exist_ok=True) | ||
|
||
lOG_FILE_PATH = os.path.join(log_path, LOG_FILE) | ||
|
||
logging.basicConfig( | ||
filename=lOG_FILE_PATH, | ||
format= "[ %(asctime)s ] %(name)s - %(levelname)s - %(message)s", | ||
level= logging.INFO | ||
) |