From 6704cd1dc0e4eaa3c37875bd51be36b010a74a19 Mon Sep 17 00:00:00 2001 From: Serene-Arc Date: Tue, 6 Apr 2021 16:16:26 +1000 Subject: [PATCH] Set log backup count from config --- README.md | 3 +++ bulkredditdownloader/default_config.cfg | 3 ++- bulkredditdownloader/downloader.py | 9 +++------ 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 605f1a2..daff766 100644 --- a/README.md +++ b/README.md @@ -198,12 +198,15 @@ The logging output for each run of the BDFR will be saved to this directory in t The `config.cfg` is the file that supplies the BDFR with the configuration to use. At the moment, the following keys **must** be included in the configuration file supplied. + - `backup_log_count` - `client_id` - `client_secret` - `scopes` All of these should not be modified unless you know what you're doing, as the default values will enable the BDFR to function just fine. A configuration is included in the BDFR when it is installed, and this will be placed in the configuration directory as the default. +Most of these values have to do with OAuth2 configuration and authorisation. The key `backup_log_count` however has to do with the log rollover. The logs in the configuration directory can be verbose and for long runs of the BDFR, can grow quite large. To combat this, the BDFR will overwrite previous logs. This value determines how many previous run logs will be kept. The default is 3, which means that the BDFR will keep at most three past logs plus the current one. Any runs past this will overwrite the oldest log file, called "rolling over". If you want more records of past runs, increase this number. + ## Contributing If you wish to contribute, see [Contributing](docs/CONTRIBUTING.md) for more information. diff --git a/bulkredditdownloader/default_config.cfg b/bulkredditdownloader/default_config.cfg index f9a3f84..97d6bb9 100644 --- a/bulkredditdownloader/default_config.cfg +++ b/bulkredditdownloader/default_config.cfg @@ -1,4 +1,5 @@ [DEFAULT] client_id = U-6gk4ZCh3IeNQ client_secret = 7CZHY6AmKweZME5s50SfDGylaPg -scopes = identity, history, read, save \ No newline at end of file +scopes = identity, history, read, save +backup_log_count = 3 \ No newline at end of file diff --git a/bulkredditdownloader/downloader.py b/bulkredditdownloader/downloader.py index 0a2d65c..81a06c1 100644 --- a/bulkredditdownloader/downloader.py +++ b/bulkredditdownloader/downloader.py @@ -67,6 +67,7 @@ class RedditDownloader: def _setup_internal_objects(self): self._determine_directories() + self._load_config() self._create_file_logger() self.download_filter = self._create_download_filter() @@ -78,8 +79,6 @@ class RedditDownloader: self.file_name_formatter = self._create_file_name_formatter() logger.log(9, 'Create file name formatter') - self._load_config() - logger.debug(f'Configuration loaded from {self.config_location}') self._create_reddit_instance() self._resolve_user_name() @@ -147,8 +146,6 @@ class RedditDownloader: self.cfg_parser.read(cfg_path) self.config_location = cfg_path return - else: - logger.warning(f'Could not find config file at {self.args.config}, attempting to find elsewhere') possible_paths = [Path('./config.cfg'), Path('./default_config.cfg'), Path(self.config_directory, 'config.cfg'), @@ -163,7 +160,6 @@ class RedditDownloader: if not self.config_location: self.config_location = list(importlib.resources.path('bulkredditdownloader', 'default_config.cfg').gen)[0] shutil.copy(self.config_location, Path(self.config_directory, 'default_config.cfg')) - logger.debug('Copied default config file from module to config folder') if not self.config_location: raise errors.BulkDownloaderException('Could not find a configuration file to load') self.cfg_parser.read(self.config_location) @@ -171,10 +167,11 @@ class RedditDownloader: def _create_file_logger(self): main_logger = logging.getLogger() log_path = Path(self.config_directory, 'log_output.txt') + backup_count = self.cfg_parser.getint('DEFAULT', 'backup_log_count', fallback=3) file_handler = logging.handlers.RotatingFileHandler( log_path, mode='a', - backupCount=10, + backupCount=backup_count, ) if log_path.exists(): file_handler.doRollover()