Skip to content

Commit

Permalink
Expand simple logging options (#4832)
Browse files Browse the repository at this point in the history
* Fix bot crash at start on permaban

* Expanded logging options

Added "logging" section to config, with options "color",
"show_datetime", "show_process_name" and "show_log_level"

* Added warning about deprecated logging_color arg

* Display log message moved

No point trying to use the logger before it's been initialised. Moved to
init_config.

* Remove milliseconds from datetime

Because really, do we need that?

* Reversed condition order for clarity

First check: "if not in config", OR
Second check: "is in config AND set to true"

If either condition matches, the logging detail will be displayed.

* Documented new log options

* Modified conditions again

Removed unnecessary second check for config values and slightly modified
parentheses as per suggestion from @mjmadsen
  • Loading branch information
Gobberwart authored and mjmadsen committed Aug 28, 2016
1 parent 5e70608 commit 6c9f865
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 29 deletions.
10 changes: 6 additions & 4 deletions configs/config.json.cluster.example
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,12 @@
"location_cache": true,
"distance_unit": "km",
"reconnecting_timeout": 15,
"logging": {
"color": true,
"clean": false
},
"logging": {
"color": true,
"show_datetime": true,
"show_process_name": true,
"show_log_level": true
},
"catch": {
"any": {"catch_above_cp": 0, "catch_above_iv": 0, "logic": "or"},
"// Example of always catching Rattata:": {},
Expand Down
10 changes: 6 additions & 4 deletions configs/config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,12 @@
"location_cache": true,
"distance_unit": "km",
"reconnecting_timeout": 15,
"logging": {
"color": true,
"clean": false
},
"logging": {
"color": true,
"show_datetime": true,
"show_process_name": true,
"show_log_level": true
},
"catch": {
"any": {"candy_threshold" : 400 ,"catch_above_cp": 0, "catch_above_iv": 0, "logic": "or"},
"// Example of always catching Rattata:": {},
Expand Down
10 changes: 6 additions & 4 deletions configs/config.json.map.example
Original file line number Diff line number Diff line change
Expand Up @@ -485,10 +485,12 @@
"location_cache": true,
"distance_unit": "km",
"reconnecting_timeout": 15,
"logging": {
"color": true,
"clean": false
},
"logging": {
"color": true,
"show_datetime": true,
"show_process_name": true,
"show_log_level": true
},
"catch": {
"any": {"catch_above_cp": 0, "catch_above_iv": 0, "logic": "or"},
"// Example of always catching Rattata:": {},
Expand Down
10 changes: 6 additions & 4 deletions configs/config.json.optimizer.example
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,12 @@
"location_cache": true,
"distance_unit": "km",
"reconnecting_timeout": 15,
"logging": {
"color": true,
"clean": false
},
"logging": {
"color": true,
"show_datetime": true,
"show_process_name": true,
"show_log_level": true
},
"catch": {
"any": {
"always_catch": true
Expand Down
10 changes: 6 additions & 4 deletions configs/config.json.path.example
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,12 @@
"location_cache": true,
"distance_unit": "km",
"reconnecting_timeout": 15,
"logging": {
"color": true,
"clean": false
},
"logging": {
"color": true,
"show_datetime": true,
"show_process_name": true,
"show_log_level": true
},
"catch": {
"any": {"catch_above_cp": 0, "catch_above_iv": 0, "logic": "or"},
"// Example of always catching Rattata:": {},
Expand Down
10 changes: 6 additions & 4 deletions configs/config.json.pokemon.example
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,12 @@
"location_cache": true,
"distance_unit": "km",
"reconnecting_timeout": 15,
"logging": {
"color": true,
"clean": false
},
"logging": {
"color": true,
"show_datetime": true,
"show_process_name": true,
"show_log_level": true
},
"catch": {
"any": {"catch_above_cp": 0, "catch_above_iv": 0, "logic": "or" },

Expand Down
8 changes: 8 additions & 0 deletions docs/configuration_files.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ Document the configuration options of PokemonGo-Bot.
| `live_config_update.tasks_only` | false | True: quick update for Tasks only (without re-login). False: slower update for entire config file.


## Logging configuration
[[back to top](#table-of-contents)]

'logging'.'color' (default false) Enabled colored logging
'logging'.'show_datetime' (default true) Show date and time in log
'logging'.'show_process_name' (default true) Show name of process generating output in log
'logging'.'show_log_level' (default true) Show level of log message in log (eg. "INFO")

## Configuring Tasks
[[back to top](#table-of-contents)]

Expand Down
8 changes: 6 additions & 2 deletions pokecli.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ def _json_loader(filename):
type=bool,
default=False
)

# Start to parse other attrs
config = parser.parse_args()
if not config.username and 'username' not in load:
Expand All @@ -652,6 +652,7 @@ def _json_loader(filename):
config.live_config_update = load.get('live_config_update', {})
config.live_config_update_enabled = config.live_config_update.get('enabled', False)
config.live_config_update_tasks_only = config.live_config_update.get('tasks_only', False)
config.logging = load.get('logging', {})

if config.map_object_cache_time < 0.0:
parser.error("--map_object_cache_time is out of range! (should be >= 0.0)")
Expand Down Expand Up @@ -696,7 +697,10 @@ def task_configuration_error(flag_name):

if "daily_catch_limit" in load:
logger.warning('The daily_catch_limit argument has been moved into the CatchPokemon Task')


if "logging_color" in load:
logger.warning('The logging_color argument has been moved into the logging config section')

if config.walk_min < 1:
parser.error("--walk_min is out of range! (should be >= 1.0)")
return None
Expand Down
17 changes: 14 additions & 3 deletions pokemongo_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def start(self):
def _setup_event_system(self):
handlers = []

if self.config.logging_color:
if self.config.logging and 'color' in self.config.logging and self.config.logging['color']:
handlers.append(ColoredLoggingHandler(self))
else:
handlers.append(LoggingHandler(self))
Expand Down Expand Up @@ -760,8 +760,19 @@ def _setup_logging(self):
logging.getLogger("pgoapi").setLevel(log_level)
logging.getLogger("rpc_api").setLevel(log_level)

if self.config.logging_clean and not self.config.debug:
formatter = Formatter(fmt='[%(asctime)s] %(message)s', datefmt='%H:%M:%S')
if self.config.logging:
logging_format = '%(message)s'
logging_format_options = ''

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

formatter = Formatter(logging_format,logging_format_options)
for handler in logging.root.handlers[:]:
handler.setFormatter(formatter)

Expand Down

0 comments on commit 6c9f865

Please sign in to comment.