-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
configure logging in separate module
- move logging configuration in a separate module - alongside console logging, always log to a file in the workdir
- Loading branch information
Showing
5 changed files
with
43 additions
and
28 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,27 @@ | ||
import logging | ||
from pathlib import Path | ||
import sys | ||
|
||
from app import __app_name__ | ||
|
||
|
||
def configure_logger(working_dir, log_level): | ||
logger = get_logger() | ||
sh = logging.StreamHandler() | ||
sh_log_fmt = '%(asctime)s [%(levelname)s] %(message)s' | ||
sh.setLevel(log_level) | ||
sh.setFormatter(logging.Formatter(sh_log_fmt)) | ||
|
||
# Always log debug out to a file in the workdir | ||
filehandler = logging.FileHandler(Path(working_dir) / "tstbtc.log") | ||
filehandler.setLevel(logging.DEBUG) | ||
file_log_fmt = '%(asctime)s %(name)s [%(levelname)s] %(message)s' | ||
filehandler.setFormatter(logging.Formatter(file_log_fmt)) | ||
|
||
logger.addHandler(sh) | ||
logger.addHandler(filehandler) | ||
logger.setLevel(logging.DEBUG) | ||
|
||
|
||
def get_logger(): | ||
return logging.getLogger(__app_name__) |
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
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