File tree Expand file tree Collapse file tree 2 files changed +50
-0
lines changed Expand file tree Collapse file tree 2 files changed +50
-0
lines changed Original file line number Diff line number Diff line change
1
+ import sys
2
+
3
+
4
+ def error_message_detail (error , error_detail : sys ):
5
+ _ , _ , exc_tb = error_detail .exc_info ()
6
+
7
+ file_name = exc_tb .tb_frame .f_code .co_filename
8
+
9
+ error_message = "Error occurred python script name [{0}] line number [{1}] error message [{2}]" .format (
10
+ file_name , exc_tb .tb_lineno , str (error )
11
+ )
12
+
13
+ return error_message
14
+
15
+
16
+ class CustomException (Exception ):
17
+ def __init__ (self , error_message , error_detail ):
18
+ """
19
+ :param error_message: error message in string format
20
+ """
21
+ super ().__init__ (error_message )
22
+
23
+ self .error_message = error_message_detail (
24
+ error_message , error_detail = error_detail
25
+ )
26
+
27
+ def __str__ (self ):
28
+ return self .error_message
29
+
30
+
31
+
Original file line number Diff line number Diff line change
1
+ import logging
2
+ import os
3
+ from datetime import datetime
4
+ from from_root import from_root
5
+
6
+
7
+ LOG_FILE = f"{ datetime .now ().strftime ('%m_%d_%Y_%H_%M_%S' )} .log"
8
+
9
+ log_path = os .path .join (from_root (), 'log' , LOG_FILE )
10
+
11
+ os .makedirs (log_path , exist_ok = True )
12
+
13
+ lOG_FILE_PATH = os .path .join (log_path , LOG_FILE )
14
+
15
+ logging .basicConfig (
16
+ filename = lOG_FILE_PATH ,
17
+ format = "[ %(asctime)s ] %(name)s - %(levelname)s - %(message)s" ,
18
+ level = logging .INFO
19
+ )
You can’t perform that action at this time.
0 commit comments