Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
task8-aggregate
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mohammed.shibili
task8-aggregate
Commits
9d66ddc5
Commit
9d66ddc5
authored
Feb 06, 2023
by
mohammed.shibili
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
loggers added
parent
1265e9eb
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
26 additions
and
0 deletions
+26
-0
scripts/core/handlers/api_function.py
+4
-0
scripts/logging/exceptions
+0
-0
scripts/logging/logging.py
+20
-0
util/mongo_util.py
+2
-0
No files found.
scripts/core/handlers/api_function.py
View file @
9d66ddc5
...
...
@@ -2,6 +2,7 @@ import json
import
pandas
as
pd
from
scripts.constants.const
import
Endpoints
from
scripts.database.mongo_db.aggregation
import
Aggregation
from
scripts.logging.logging
import
logger
from
util.mongo_util
import
mongo_connection
...
...
@@ -17,6 +18,7 @@ class OperationsOnApi:
dict_from_file
=
json
.
loads
(
file
)
self
.
collection_name
.
insert_many
(
dict_from_file
)
except
Exception
as
e
:
logger
.
exception
(
e
)
return
"data insertion error"
,
e
def
violation_issued
(
self
):
...
...
@@ -31,6 +33,7 @@ class OperationsOnApi:
no_violation
=
list
(
self
.
collection_name
.
aggregate
(
self
.
data_no_violation
))
return
no_violation
except
Exception
as
e
:
logger
.
exception
(
e
)
return
"error in fetching no violation"
,
e
def
create_exel_file
(
self
):
...
...
@@ -41,4 +44,5 @@ class OperationsOnApi:
# download file
return
f
'data inserted to path {Endpoints().folder}{Endpoints().exel_file}'
except
Exception
as
e
:
logger
.
exception
(
e
)
return
"exel conversion failed"
,
e
scripts/logging/exceptions
0 → 100644
View file @
9d66ddc5
scripts/logging/logging.py
0 → 100644
View file @
9d66ddc5
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)-6
s -
%(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
()
util/mongo_util.py
View file @
9d66ddc5
from
pymongo
import
MongoClient
from
scripts.config.appconf
import
server_name
from
scripts.constants.const
import
DbDetails
from
scripts.logging.logging
import
logger
# creating mongo connection
...
...
@@ -12,4 +13,5 @@ def mongo_connection():
print
(
"connection success"
)
return
collection
except
Exception
as
e
:
logger
.
exception
(
e
)
print
(
"db connection failed"
,
e
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment