Spaces:
Sleeping
Sleeping
exception and logging
Browse files- src/Components/Data_ingestation.py +0 -0
- src/Components/__init__.py +0 -0
- src/Pipeline/__init__.py +0 -0
- src/exception.py +25 -0
- src/logger.py +16 -0
src/Components/Data_ingestation.py
ADDED
File without changes
|
src/Components/__init__.py
ADDED
File without changes
|
src/Pipeline/__init__.py
ADDED
File without changes
|
src/exception.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import sys
|
2 |
+
import logging
|
3 |
+
def error_message_detail(error,error_detail:sys):
|
4 |
+
_,_,exc_tb = error_detail.exc_info()
|
5 |
+
file_name =exc_tb.tb_frame.f_code.co_filename
|
6 |
+
error_message = "error occured in python script name [{0}] line number [{1}] error message [{2}]".format(file_name,exc_tb.tb_lineno,str(error))
|
7 |
+
|
8 |
+
return error_message
|
9 |
+
|
10 |
+
class CustomException(Exception):
|
11 |
+
def __init__(self,error_message,error_detail:sys) -> None:
|
12 |
+
super().__init__(error_message)
|
13 |
+
self.error_message = error_message_detail(error_message,error_detail=error_detail)
|
14 |
+
def __str__(self) -> str:
|
15 |
+
return self.error_message
|
16 |
+
|
17 |
+
if __name__ == "__main__":
|
18 |
+
|
19 |
+
try:
|
20 |
+
a = 1/0
|
21 |
+
except Exception as e:
|
22 |
+
logging.info("Logging has started")
|
23 |
+
raise CustomException
|
24 |
+
finally:
|
25 |
+
logging.info(CustomException(e,sys))
|
src/logger.py
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import logging
|
2 |
+
import os
|
3 |
+
from datetime import datetime
|
4 |
+
|
5 |
+
LOG_FILE = f'{datetime.now().strftime("%m_%d_%y_%H_%M_%S")}.log'
|
6 |
+
logs_path = os.path.join(os.getcwd(),"logs",LOG_FILE)
|
7 |
+
os.markdirs(logs_path,exist_ok = True)
|
8 |
+
|
9 |
+
LOG_FILE_PATH = os.path.join(logs_path,LOG_FILE)
|
10 |
+
|
11 |
+
logging.basicConfig(
|
12 |
+
filename= LOG_FILE_PATH,
|
13 |
+
force="[ %(asctime)s] %(linemo)d %(name)s - %(levelname)s - %(message)s",
|
14 |
+
level= logging.INFO,
|
15 |
+
)
|
16 |
+
|