Skip to content

Commit

Permalink
--logging info to chack new machine
Browse files Browse the repository at this point in the history
  • Loading branch information
AmzadHossainrafis committed Aug 29, 2023
1 parent eb16a82 commit 27e9cf6
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
28 changes: 28 additions & 0 deletions exception.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import sys
import logging
from src.logger import logging

def error_massage_detail(error, error_detail:sys):
_,_,exc_tb = error_detail.exc_info()
file_name = exc_tb.tb_frame.f_code.co_filename
error_message = f'Error: {str(error)} in {file_name} at line {exc_tb.tb_lineno}'


return error_message

class CustomException(Exception):
def __init__(self, error_message , error_detail:sys):
super().__init__(error_message)
self.error_message = error_massage_detail(error_message, error_detail=error_detail)

def __str__(self):
return f'{self.error_message}'


# if __name__ == '__main__':
# try:
# t= 1/0
# except Exception as e:
# logging.info('CustomException test')
# raise CustomException(e, sys)

20 changes: 20 additions & 0 deletions logger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import logging
import os
from datetime import datetime


LOG_FILE = f'{datetime.now().strftime("%Y-%m-%d")}._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 ,
datefmt='%Y-%m-%d %H:%M:%S'
)

if __name__ == '__main__':
logging.info('logging is working just lunched')

0 comments on commit 27e9cf6

Please sign in to comment.