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

Expand simple logging options #4832

Merged
merged 14 commits into from
Aug 28, 2016
10 changes: 7 additions & 3 deletions pokemongo_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -763,11 +763,15 @@ def _setup_logging(self):
if self.config.logging:
logging_format = '%(message)s'
logging_format_options = ''
if ('show_log_level' in self.config.logging and self.config.logging['show_log_level']) or 'show_log_level' not in self.config.logging:

if 'show_log_level' not in self.config.logging or \
('show_log_level' in self.config.logging and self.config.logging['show_log_level']):
Copy link
Contributor

@mjmadsen mjmadsen Aug 28, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I know I'm being a nazi here. The checks in the parenthesis will evaluate first, as parenthesis have a higher evaluation precedence, even though python evaluates left to right. "in" has a lower precedence than attributes and indices.

Please use the following (reduces the double "in" check too):
if ('show_log_level' not in self.config.logging) or self.config.logging['show_log_level']:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

logging_format = '[%(levelname)s] ' + logging_format
if ('show_process_name' in self.config.logging and self.config.logging['show_process_name']) or 'show_process_name' not in self.config.logging:
if 'show_process_name' not in self.config.logging or \
('show_process_name' in self.config.logging and self.config.logging['show_process_name']):
logging_format = '[%(name)10s] ' + logging_format
if ('show_datetime' in self.config.logging and self.config.logging['show_datetime']) or 'show_datetime' not in self.config.logging:
if 'show_datetime' not in self.config.logging or \
('show_datetime' in self.config.logging and self.config.logging['show_datetime']):
logging_format = '[%(asctime)s] ' + logging_format
logging_format_options = '%Y-%m-%d %H:%M:%S'

Expand Down