Set log backup count from config
This commit is contained in:
parent
5fea34ffce
commit
6704cd1dc0
|
@ -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.
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
[DEFAULT]
|
||||
client_id = U-6gk4ZCh3IeNQ
|
||||
client_secret = 7CZHY6AmKweZME5s50SfDGylaPg
|
||||
scopes = identity, history, read, save
|
||||
scopes = identity, history, read, save
|
||||
backup_log_count = 3
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue