-
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
86e193c
commit 8929fb3
Showing
4 changed files
with
38 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 @@ | ||
[ 2025-01-25 20:16:36,992 ] 17 root - INFO - This is a test log IN TRY BLOCK |
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,21 @@ | ||
import sys | ||
from src.logging import logger | ||
class NetworkSecurityException(Exception): | ||
def __init__(self, error_message, error_details:sys): | ||
self.error_message = error_message | ||
_, _, exc_tb = error_details.exc_info() | ||
|
||
self.line_number = exc_tb.tb_lineno | ||
self.file_name = exc_tb.tb_frame.f_code.co_filename | ||
|
||
def __str__(self): | ||
return "NetworkSecurityException: Error occured in python script name [{0}] line number [{1}] error message [{2}]".format( | ||
self.file_name, self.line_number, str(self.error_message)) | ||
|
||
if __name__ == '__main__': | ||
try: | ||
logger.logging.info("This is a test log IN TRY BLOCK") | ||
a = 1/0 | ||
print("This line will not be printed") | ||
except Exception as e: | ||
raise NetworkSecurityException(e, sys) |
Binary file not shown.
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,16 @@ | ||
import logging | ||
import os | ||
from datetime import datetime | ||
|
||
LOG_FILE=f"{datetime.now().strftime('%m_%d_%Y_%H_%M_%S')}.log" | ||
|
||
logs_path=os.path.join(os.getcwd(),"logs",LOG_FILE) | ||
os.makedirs(logs_path,exist_ok=True) | ||
|
||
LOG_FILE_PATH=os.path.join(logs_path,LOG_FILE) | ||
|
||
logging.basicConfig( | ||
filename=LOG_FILE_PATH, | ||
format="[ %(asctime)s ] %(lineno)d %(name)s - %(levelname)s - %(message)s", | ||
level=logging.INFO, | ||
) |