File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import sys
2+
3+ from network_security .logging import logger
4+
5+
6+ class NetworkSecurityError (Exception ):
7+ def __init__ (self , error_message : str , error_details : sys ) -> None :
8+ self .error_message = error_message
9+ _ , _ , exc_tb = error_details .exc_info ()
10+
11+ self .lineno = exc_tb .tb_lineno
12+ self .file_name = exc_tb .tb_frame .f_code .co_filename
13+
14+ def __str__ (self ) -> str :
15+ return f"Error occured in python script name [{ self .file_name } ] line number [{ self .lineno } ] error message [{ self .error_message !s} ]"
16+
17+
18+ # if __name__ == "__main__":
19+ # try:
20+ # logger.logging.info("Enter the try block")
21+ # a = 1 / 0
22+ # print("This will not be printed", a)
23+ # except Exception as e:
24+ # raise NetworkSecurityError(e, sys) from e
Original file line number Diff line number Diff line change 1+ import logging
2+ from datetime import UTC , datetime
3+ from pathlib import Path
4+
5+ LOG_FILE = f"{ datetime .now (UTC ).strftime ('%m_%d_%Y_%H_%M_%S' )} .log"
6+
7+ logs_path = Path .cwd () / "logs"
8+ logs_path .mkdir (parents = True , exist_ok = True )
9+
10+ LOG_FILE_PATH = logs_path / LOG_FILE
11+
12+ logging .basicConfig (
13+ filename = LOG_FILE_PATH ,
14+ format = "[ %(asctime)s ] %(lineno)d %(name)s - %(levelname)s - %(message)s" ,
15+ level = logging .INFO ,
16+ )
You can’t perform that action at this time.
0 commit comments