Commit 55b72480 by arjun.b

logging file added

parent b9bdfab5
......@@ -5,3 +5,5 @@ port_no=8000
uri=mongodb://localhost:27017
[file_path]
path=temp/excel_data.xlsx
[logging]
file_name=scripts/external/logging_log
......@@ -3,9 +3,13 @@ import configparser
try:
config = configparser.ConfigParser()
config.read("conf/application.conf")
# server path
server_path = config.get("server", "server_path")
port_no = config.get("server", "port_no")
# mongo pth
uri = config.get("mongo", "uri")
file_path = config.get("file_path", "path")
# logging file path
file_name = config.get("logging", "file_name")
except configparser.NoOptionError:
print("could not find conf file")
import logging
import os
from logging.handlers import RotatingFileHandler
from scripts.config.application_config import file_name
def get_logger():
"""
Creates a rotating log
"""
__logger__ = logging.getLogger('')
__logger__.setLevel("ERROR")
log_formatter = '%(asctime)s - %(levelname)-6s - [%(threadName)5s:%(funcName)5s():%(lineno)s] - %(message)s'
time_format = "%Y-%m-%d %H:%M:%S"
formatter = logging.Formatter(log_formatter, time_format)
log_file = os.path.join(f"{file_name}_ERROR.log")
temp_handler = RotatingFileHandler(log_file,
maxBytes=100000000,
backupCount=5)
temp_handler.setFormatter(formatter)
__logger__.addHandler(temp_handler)
return __logger__
logger = get_logger()
from fastapi import FastAPI, UploadFile
from scripts.constants.end_points import APIEndpoints
from scripts.database.mongo.mongo_aggregation import max_violation, no_violation
from scripts.core.handlers.mongo_handlers import MongoHandler
from fastapi import FastAPI, UploadFile
from scripts.constants.end_points import APIEndpoints
from scripts.core.handlers.mongo_handlers import MongoHandler
from scripts.database.mongo.mongo_aggregation import max_violation, no_violation
from scripts.logging.logging import logger
app = FastAPI(
title="Mongo Aggregations")
......@@ -29,19 +25,31 @@ async def upload_file(file: UploadFile):
# business name with maximum violation
@app.get(APIEndpoints.max_violation, tags=["tasks"])
async def business_max_violation():
re = max_violation()
return {"data": re}
try:
re = max_violation()
return {"data": re}
except Exception as e:
logger.error("cant find business name with max violation")
print(e)
# business name with no violation
@app.get(APIEndpoints.no_violation, tags=["tasks"])
async def business_no_violation():
re = no_violation()
return {"data": re}
try:
re = no_violation()
return {"data": re}
except Exception as e:
logger.error("cant find business name with no violation")
print(e)
# create Excel file
@app.get(APIEndpoints.convert_excel, tags=["convert to excel"])
async def convert_excel():
MongoHandler.create_excel_file()
return {"data", "Excel file generated based on business name,result and date"}
try:
MongoHandler.create_excel_file()
return {"data", "Excel file generated based on business name,result and date"}
except Exception as e:
logger.error("cant create excel file")
print(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