-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1c20ce4
commit be9eb52
Showing
3 changed files
with
45 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from loguru import logger | ||
|
||
|
||
def setup_logging(): | ||
# Format of the logs | ||
log_format = ( | ||
'<green>{time:YYYY-MM-DD HH:mm:ss!UTC}</green> | ' | ||
'<level>{level: <8}</level> | ' | ||
'<cyan>{name}</cyan>:<cyan>{function}</cyan>:<cyan>{line}</cyan> - ' | ||
'<level>{message}</level>' | ||
) | ||
|
||
# General logs | ||
logger.add( | ||
'logs/server.log', | ||
rotation='10 MB', | ||
retention='30 days', | ||
level='INFO', # INFO logs will log everything from INFO and above (WARNING, ERROR, etc.) | ||
format=log_format, | ||
enqueue=True, | ||
filter=lambda record: not bool(record['exception']), | ||
) | ||
|
||
# Exception logs | ||
logger.add( | ||
'logs/exceptions.log', | ||
rotation='10 MB', | ||
retention='30 days', | ||
level='ERROR', # ERROR will only log errors | ||
format=log_format, | ||
enqueue=True, | ||
backtrace=True, | ||
diagnose=True, | ||
filter=lambda record: bool(record['exception']), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters