Skip to content

Commit d4a942c

Browse files
surajitsurajit
authored andcommitted
modify log.py
1 parent 3c36e88 commit d4a942c

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

logger/log.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
import json
21
import logging
3-
from functools import wraps
4-
from settings import LOG_FILE
2+
from logging.handlers import RotatingFileHandler
53

6-
logger = logging.getLogger(__name__)
4+
from functools import wraps
75

6+
from settings import LOG_FILE_NAME
87

9-
async def append_log(data):
10-
with open(LOG_FILE, 'a') as file:
11-
json.dump(data, file)
12-
file.write('\n')
8+
logger = logging.getLogger(__name__)
9+
logger.setLevel(logging.DEBUG)
10+
formatter = logging.Formatter('%(asctime)s | %(levelname)s | %(message)s')
11+
fh = RotatingFileHandler(LOG_FILE_NAME)
12+
fh.setLevel(logging.DEBUG)
13+
fh.setFormatter(formatter)
14+
logger.addHandler(fh)
1315

1416

1517
def save_log(func):
@@ -29,10 +31,9 @@ async def wrapper(*args, **kwargs):
2931
if hasattr(request, 'json'):
3032
json_data = await request.json()
3133
message["data"] = [json_data]
32-
await append_log(message)
34+
logger.debug(message)
3335
except Exception as exc:
3436
logger.exception(f'Exception occurred {exc}')
3537
pass
3638
return await func(*args, **kwargs)
37-
3839
return wrapper

0 commit comments

Comments
 (0)