-
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
Showing
4 changed files
with
43 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,3 +127,6 @@ dmypy.json | |
|
||
# Pyre type checker | ||
.pyre/ | ||
|
||
# app logs | ||
/logs |
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,5 @@ | ||
from logging import Logger, getLogger | ||
|
||
|
||
def get_file_path_logger(module: str) -> Logger: | ||
return getLogger(module.replace(".", "/")) |
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 |
---|---|---|
@@ -1 +1,31 @@ | ||
print("hello.") | ||
import logging | ||
from logging import StreamHandler, basicConfig | ||
from logging.handlers import TimedRotatingFileHandler | ||
from os import makedirs | ||
|
||
from app.logger import get_file_path_logger | ||
|
||
LOG_DIRECTORY = "logs" | ||
|
||
logger = get_file_path_logger(__name__) | ||
|
||
if __name__ == "__main__": | ||
makedirs(LOG_DIRECTORY, exist_ok=True) | ||
|
||
basicConfig( | ||
level=logging.INFO, | ||
datefmt="%Y/%m/%d %H:%M:%S", | ||
format="%(asctime)s [%(levelname)s] %(name)s:%(lineno)s %(message)s", | ||
handlers=[ | ||
TimedRotatingFileHandler( | ||
f"{LOG_DIRECTORY}/app.log", | ||
when="midnight", | ||
backupCount=30, | ||
interval=1, | ||
encoding="utf-8", | ||
), | ||
StreamHandler(), | ||
], | ||
) | ||
|
||
logger.info("hello.") |