Commit 9d66ddc5 by mohammed.shibili

loggers added

parent 1265e9eb
...@@ -2,6 +2,7 @@ import json ...@@ -2,6 +2,7 @@ import json
import pandas as pd import pandas as pd
from scripts.constants.const import Endpoints from scripts.constants.const import Endpoints
from scripts.database.mongo_db.aggregation import Aggregation from scripts.database.mongo_db.aggregation import Aggregation
from scripts.logging.logging import logger
from util.mongo_util import mongo_connection from util.mongo_util import mongo_connection
...@@ -17,6 +18,7 @@ class OperationsOnApi: ...@@ -17,6 +18,7 @@ class OperationsOnApi:
dict_from_file = json.loads(file) dict_from_file = json.loads(file)
self.collection_name.insert_many(dict_from_file) self.collection_name.insert_many(dict_from_file)
except Exception as e: except Exception as e:
logger.exception(e)
return "data insertion error", e return "data insertion error", e
def violation_issued(self): def violation_issued(self):
...@@ -31,6 +33,7 @@ class OperationsOnApi: ...@@ -31,6 +33,7 @@ class OperationsOnApi:
no_violation = list(self.collection_name.aggregate(self.data_no_violation)) no_violation = list(self.collection_name.aggregate(self.data_no_violation))
return no_violation return no_violation
except Exception as e: except Exception as e:
logger.exception(e)
return "error in fetching no violation", e return "error in fetching no violation", e
def create_exel_file(self): def create_exel_file(self):
...@@ -41,4 +44,5 @@ class OperationsOnApi: ...@@ -41,4 +44,5 @@ class OperationsOnApi:
# download file # download file
return f'data inserted to path {Endpoints().folder}{Endpoints().exel_file}' return f'data inserted to path {Endpoints().folder}{Endpoints().exel_file}'
except Exception as e: except Exception as e:
logger.exception(e)
return "exel conversion failed", e return "exel conversion failed", e
import logging
import os
from logging.handlers import RotatingFileHandler
def get_logger():
# creating rotating logging
__logger__ = logging.getLogger('')
__logger__.setLevel(logging.INFO)
file_path = "scripts/logging/"
formatter = logging.Formatter('%(asctime)s - %(levelname)-6s - %(message)s', "%Y-%m-%d %H:%M:%S")
log_file = os.path.join(f"{file_path}exceptions.log")
temp_handler = RotatingFileHandler(log_file, maxBytes=1, backupCount=10)
temp_handler.setFormatter(formatter)
__logger__.addHandler(temp_handler)
return __logger__
logger = get_logger()
from pymongo import MongoClient from pymongo import MongoClient
from scripts.config.appconf import server_name from scripts.config.appconf import server_name
from scripts.constants.const import DbDetails from scripts.constants.const import DbDetails
from scripts.logging.logging import logger
# creating mongo connection # creating mongo connection
...@@ -12,4 +13,5 @@ def mongo_connection(): ...@@ -12,4 +13,5 @@ def mongo_connection():
print("connection success") print("connection success")
return collection return collection
except Exception as e: except Exception as e:
logger.exception(e)
print("db connection failed", e) print("db connection failed", e)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment