-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add logger module, and adding wrapper logs to run scripts, will add d…
…eeper level logs in next commit
- Loading branch information
1 parent
e38a3e7
commit cea6d48
Showing
2 changed files
with
100 additions
and
30 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,32 @@ | ||
""" | ||
**logger** module just exposes a ``setup_logger`` function to quickly configure the python logger. | ||
""" | ||
import logging | ||
import os | ||
|
||
|
||
# WIP - Prateek: TODO: pickup filenames dynamically | ||
# TODO: Improve log_dir path | ||
def setup_logger(log_file_name, level=logging.INFO): | ||
"""Set up a logger with a specific log file name.""" | ||
logger = logging.getLogger(log_file_name) | ||
|
||
if not logger.hasHandlers(): | ||
logger.setLevel(level) | ||
|
||
log_dir = os.path.join(os.path.dirname(__file__), '..', '..', 'logs') | ||
os.makedirs(log_dir, exist_ok=True) | ||
|
||
log_file = os.path.join(log_dir, log_file_name) | ||
file_handler = logging.FileHandler(log_file) | ||
|
||
stream_handler = logging.StreamHandler() | ||
|
||
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') | ||
file_handler.setFormatter(formatter) | ||
stream_handler.setFormatter(formatter) | ||
|
||
logger.addHandler(file_handler) | ||
logger.addHandler(stream_handler) | ||
|
||
return logger |