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
Merged
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