Skip to content

Commit

Permalink
logger and exception updated
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnysavita10 committed Jan 10, 2024
1 parent 16ac188 commit 4000af1
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 0 deletions.
68 changes: 68 additions & 0 deletions experiment/experiments.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2226,6 +2226,74 @@
"max(r2_list)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"import logging\n",
"import os\n",
"from datetime import datetime"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"LOG_FILE=f\"{datetime.now().strftime('%m_%d_%Y_%H_%M_%S')}.log\"\n",
"\n",
"log_path=os.path.join(os.getcwd(),\"logs\")\n",
"\n",
"os.makedirs(log_path,exist_ok=True)\n",
"\n",
"LOG_FILEPATH=os.path.join(log_path,LOG_FILE)\n"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'/config/workspace/experiment/logs/01_10_2024_15_49_44.log'"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"LOG_FILEPATH"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"logging.basicConfig(level=logging.INFO, \n",
" filename=LOG_FILEPATH,\n",
" format=\"[%(asctime)s] %(lineno)d %(name)s - %(levelname)s - %(message)s\"\n",
" \n",
")\n"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"logging.info(\"this is my test log\")"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down
Empty file added src/exception/__init__.py
Empty file.
25 changes: 25 additions & 0 deletions src/exception/exception.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import sys


class customexception(Exception):

def __init__(self,error_message,error_details:sys):
self.error_message=error_message
_,_,exc_tb=error_details.exc_info()
print(exc_tb)

self.lineno=exc_tb.tb_lineno
self.file_name=exc_tb.tb_frame.f_code.co_filename

def __str__(self):
return "Error occured in python script name [{0}] line number [{1}] error message [{2}]".format(
self.file_name, self.lineno, str(self.error_message))


if __name__=="__main__":
try:
a=1/0

except Exception as e:
#print(e)
raise customexception(e,sys)
Empty file added src/logger/__init__.py
Empty file.
20 changes: 20 additions & 0 deletions src/logger/logging.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('%m_%d_%Y_%H_%M_%S')}.log"

log_path=os.path.join(os.getcwd(),"logs")

os.makedirs(log_path,exist_ok=True)

LOG_FILEPATH=os.path.join(log_path,LOG_FILE)


logging.basicConfig(level=logging.INFO,
filename=LOG_FILEPATH,
format="[%(asctime)s] %(lineno)d %(name)s - %(levelname)s - %(message)s"

)


11 changes: 11 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from src.logger.logging import logging

logging.info("this is myb testing")


logging.info(" this my second tesgting")
logging.info(" this my second tesgting")

logging.info(" this my second tesgting")
logging.info(" this my second tesgting")
logging.info(" this my second tesgting")

0 comments on commit 4000af1

Please sign in to comment.