From 794a959ba7aa88fa73425d81e0061af0d9997975 Mon Sep 17 00:00:00 2001 From: Gobberwart Date: Sun, 28 Aug 2016 04:06:11 +1000 Subject: [PATCH 1/8] Fix bot crash at start on permaban --- pokecli.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pokecli.py b/pokecli.py index d57aa76caa..f9e1cec5ce 100644 --- a/pokecli.py +++ b/pokecli.py @@ -80,6 +80,9 @@ def initialize_task(bot, config): def initialize(config): bot = PokemonGoBot(config) + return bot + + def start_bot(bot,config): bot.start() initialize_task(bot,config) bot.metrics.capture_stats() @@ -113,6 +116,7 @@ def get_commit_hash(): while not finished: try: bot = initialize(config) + bot = start_bot(bot,config) config_changed = check_mod(config_file) bot.event_manager.emit( From 041e5ff0b52032316a718e5c496f239ae35fbaba Mon Sep 17 00:00:00 2001 From: Gobberwart Date: Sun, 28 Aug 2016 09:09:43 +1000 Subject: [PATCH 2/8] Expanded logging options Added "logging" section to config, with options "color", "show_datetime", "show_process_name" and "show_log_level" --- configs/config.json.cluster.example | 10 ++++++---- configs/config.json.map.example | 10 ++++++---- configs/config.json.optimizer.example | 10 ++++++---- configs/config.json.path.example | 10 ++++++---- configs/config.json.pokemon.example | 10 ++++++---- pokecli.py | 3 ++- pokemongo_bot/__init__.py | 14 +++++++++++--- 7 files changed, 43 insertions(+), 24 deletions(-) diff --git a/configs/config.json.cluster.example b/configs/config.json.cluster.example index 5e63052f69..ed7d9e6508 100644 --- a/configs/config.json.cluster.example +++ b/configs/config.json.cluster.example @@ -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:": {}, diff --git a/configs/config.json.map.example b/configs/config.json.map.example index d675f18998..ea85fe44ed 100644 --- a/configs/config.json.map.example +++ b/configs/config.json.map.example @@ -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:": {}, diff --git a/configs/config.json.optimizer.example b/configs/config.json.optimizer.example index 70acc217f8..0f1da751d3 100644 --- a/configs/config.json.optimizer.example +++ b/configs/config.json.optimizer.example @@ -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 diff --git a/configs/config.json.path.example b/configs/config.json.path.example index 9610fed2b5..2e053d6d8d 100644 --- a/configs/config.json.path.example +++ b/configs/config.json.path.example @@ -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:": {}, diff --git a/configs/config.json.pokemon.example b/configs/config.json.pokemon.example index 5592ab14f8..37d3cf98e7 100644 --- a/configs/config.json.pokemon.example +++ b/configs/config.json.pokemon.example @@ -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" }, diff --git a/pokecli.py b/pokecli.py index a5a71629a7..ec07497564 100644 --- a/pokecli.py +++ b/pokecli.py @@ -630,7 +630,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: @@ -650,6 +650,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)") diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py index 61c9c2d758..c908e95820 100644 --- a/pokemongo_bot/__init__.py +++ b/pokemongo_bot/__init__.py @@ -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)) @@ -760,8 +760,16 @@ 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' + if ('show_log_level' in self.config.logging and self.config.logging['show_log_level']) or 'show_log_level' not in self.config.logging: + 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: + 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: + logging_format = '[%(asctime)s] ' + logging_format + + formatter = Formatter(fmt=logging_format) for handler in logging.root.handlers[:]: handler.setFormatter(formatter) From bb844b9ea7fed6cc23ccc53a6ed0fe2b376c0234 Mon Sep 17 00:00:00 2001 From: Gobberwart Date: Sun, 28 Aug 2016 09:23:49 +1000 Subject: [PATCH 3/8] Added warning about deprecated logging_color arg --- pokemongo_bot/__init__.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py index c908e95820..f3f8edfbd2 100644 --- a/pokemongo_bot/__init__.py +++ b/pokemongo_bot/__init__.py @@ -132,6 +132,9 @@ def start(self): def _setup_event_system(self): handlers = [] + if self.config.logging_color: + self.logger.warning('The logging_color argument has been moved into the logging config section') + if self.config.logging and 'color' in self.config.logging and self.config.logging['color']: handlers.append(ColoredLoggingHandler(self)) else: From 0cf965547ef22fb730e31833fdce80390042758e Mon Sep 17 00:00:00 2001 From: Gobberwart Date: Sun, 28 Aug 2016 09:39:37 +1000 Subject: [PATCH 4/8] Display log message moved No point trying to use the logger before it's been initialised. Moved to init_config. --- pokecli.py | 5 ++++- pokemongo_bot/__init__.py | 3 --- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pokecli.py b/pokecli.py index ec07497564..141ba87f20 100644 --- a/pokecli.py +++ b/pokecli.py @@ -695,7 +695,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 diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py index f3f8edfbd2..c908e95820 100644 --- a/pokemongo_bot/__init__.py +++ b/pokemongo_bot/__init__.py @@ -132,9 +132,6 @@ def start(self): def _setup_event_system(self): handlers = [] - if self.config.logging_color: - self.logger.warning('The logging_color argument has been moved into the logging config section') - if self.config.logging and 'color' in self.config.logging and self.config.logging['color']: handlers.append(ColoredLoggingHandler(self)) else: From f88997d702cfa2206e14c3f4822e1e39b60827ad Mon Sep 17 00:00:00 2001 From: Gobberwart Date: Sun, 28 Aug 2016 09:58:29 +1000 Subject: [PATCH 5/8] Remove milliseconds from datetime Because really, do we need that? --- pokemongo_bot/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py index c908e95820..d9e616025e 100644 --- a/pokemongo_bot/__init__.py +++ b/pokemongo_bot/__init__.py @@ -762,14 +762,16 @@ 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: 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: 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: logging_format = '[%(asctime)s] ' + logging_format + logging_format_options = '%Y-%m-%d %H:%M:%S' - formatter = Formatter(fmt=logging_format) + formatter = Formatter(logging_format,logging_format_options) for handler in logging.root.handlers[:]: handler.setFormatter(formatter) From c9164a76928b7faf50fe707c0bf4792f1bffe98e Mon Sep 17 00:00:00 2001 From: Gobberwart Date: Sun, 28 Aug 2016 15:39:46 +1000 Subject: [PATCH 6/8] 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. --- pokemongo_bot/__init__.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py index d9e616025e..14058976a9 100644 --- a/pokemongo_bot/__init__.py +++ b/pokemongo_bot/__init__.py @@ -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']): 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' From 1ccde940d7012aa59e67aae9f520fabfad033385 Mon Sep 17 00:00:00 2001 From: Gobberwart Date: Sun, 28 Aug 2016 15:53:33 +1000 Subject: [PATCH 7/8] Documented new log options --- docs/configuration_files.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/configuration_files.md b/docs/configuration_files.md index ef47e7d07d..072b4b429d 100644 --- a/docs/configuration_files.md +++ b/docs/configuration_files.md @@ -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)] From 33e10953c4b1ca7602442c6f3807cf05a12aab28 Mon Sep 17 00:00:00 2001 From: Gobberwart Date: Sun, 28 Aug 2016 16:05:29 +1000 Subject: [PATCH 8/8] Modified conditions again Removed unnecessary second check for config values and slightly modified parentheses as per suggestion from @mjmadsen --- configs/config.json.example | 10 ++++++---- pokemongo_bot/__init__.py | 9 +++------ 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/configs/config.json.example b/configs/config.json.example index e11dedd587..634ab60b13 100644 --- a/configs/config.json.example +++ b/configs/config.json.example @@ -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:": {}, diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py index 14058976a9..3251d161c0 100644 --- a/pokemongo_bot/__init__.py +++ b/pokemongo_bot/__init__.py @@ -764,14 +764,11 @@ def _setup_logging(self): logging_format = '%(message)s' logging_format_options = '' - if 'show_log_level' not in self.config.logging or \ - ('show_log_level' in self.config.logging and self.config.logging['show_log_level']): + 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 \ - ('show_process_name' in self.config.logging and self.config.logging['show_process_name']): + 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 \ - ('show_datetime' in self.config.logging and self.config.logging['show_datetime']): + 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'