Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting log file #91

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions fps/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,12 @@ def colourized_formatter(
return logging.Formatter(fmt)


def _set_loggers_config(loggers=(), level="info"):
def _set_loggers_config(loggers=(), level="info", filename=None):

filename = None
log_level = level.upper()

handlers = ["console"]
if filename:
handlers.append("file")

LOG_FORMATTERS = {
"colour": {
Expand Down Expand Up @@ -215,9 +215,9 @@ def _set_loggers_config(loggers=(), level="info"):
logging.config.dictConfig(LOG_CONFIG)


def configure_logger(logger: str, level: str = "info") -> None:
def configure_logger(logger: str, level: str = "info", filename=None) -> None:
"""Configure a single logger (formatters, handlers)"""
_set_loggers_config((logger,), level)
_set_loggers_config((logger,), level, filename)


def configure_loggers(loggers: Iterable[str], level: str = "info") -> None:
Expand All @@ -229,7 +229,9 @@ def get_loggers_config() -> Dict[str, Any]:
return LOG_CONFIG


def get_configured_logger(name: str, level: str = "info") -> logging.Logger:
def get_configured_logger(
name: str, level: str = "info", filename=None
) -> logging.Logger:
logger = logging.getLogger(name)
configure_logger(name, level)
configure_logger(name, level, filename)
return logger