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.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/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/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)] diff --git a/pokecli.py b/pokecli.py index d82320a3b4..6598efca34 100644 --- a/pokecli.py +++ b/pokecli.py @@ -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: @@ -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)") @@ -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 diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py index d98520af94..6891da550e 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,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)