Skip to content

Commit

Permalink
Logging Changes
Browse files Browse the repository at this point in the history
Fixes #26
  • Loading branch information
RichardSchwabe committed Jul 19, 2023
1 parent f26e0d7 commit 3f10ca9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
9 changes: 9 additions & 0 deletions reptor/lib/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Config(ConfigProtocol):
"token": None,
"project_id": None,
"community": False,
"log_file": False,
}

"""These keys are ignored when writing the config to a file
Expand Down Expand Up @@ -192,3 +193,11 @@ def get_community_enabled(self) -> bool:
bool: Default False
"""
return self.get("community", False)

def get_log_file(self) -> bool:
"""Checks if the user wants to keep a log file in their home directory
Returns:
bool: True to keep logs in a file
"""
return self.get("log_file", False)
11 changes: 3 additions & 8 deletions reptor/lib/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,9 @@ def init_log_file():
Returns:
pathlib.Path: Full pathlib Path to log FILE
"""
date_based_log_folder = settings.LOG_FOLDER / datetime.now().strftime(
"%Y-%m-%d"
)
date_based_log_folder.mkdir(parents=True, exist_ok=True)
return (
date_based_log_folder
/ f"log_{datetime.now().strftime('%Y-%m-%d-%H-%M-%S')}.log"
)
# Date Based
settings.LOG_FOLDER.mkdir(parents=True, exist_ok=True)
return settings.LOG_FOLDER / "reptor.log"


class TermEscapeCodeFormatter(logging.Formatter):
Expand Down
3 changes: 2 additions & 1 deletion reptor/lib/reptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ def __init__(self) -> None:
self.plugin_manager = PluginManager(self)

# Todo: Debate if always write to file or togglable
self.logger.add_file_log()
if self.get_config().get_log_file():
self.logger.add_file_log()

def get_config(self) -> Config:
"""Use this to access the current config
Expand Down

0 comments on commit 3f10ca9

Please sign in to comment.