Repository: PokemonGoF/PokemonGo-Bot

Issue:
Logging headers repeated on utf8 messages
### Expected Behavior

Message header only appear one time
### Actual Behavior

Headers are repeated on messages containing utf8 characters

`[2016-09-03 18:20:40] [lured_pokemon_found] [2016-09-03 18:20:40] [lured_pokemon_found] Lured pokemon at fort þ¥ÄÕ¡© (f7d3a79d3c874272aa6d7482c74afd2a.16)`
### Your FULL config.json (remove your username, password, gmapkey and any other private info)

Not relevant
### Output when issue occurred

`[2016-09-03 18:20:40] [lured_pokemon_found] [2016-09-03 18:20:40] [lured_pokemon_found] Lured pokemon at fort þ¥ÄÕ¡© (f7d3a79d3c874272aa6d7482c74afd2a.16)`
### Steps to Reproduce

Bot in an asia country ^^
### Other Information

OS: Windows
Branch:  dev
Git Commit: HEAD
Python Version: 2.7.12



Discussion:
I am tracking the issue. It comes from an exception in logging stream handler when encoding the unicode strings to utf-8, which cause the header to be repeated.


Resolving patch:
diff --git a/pokecli.py b/pokecli.py
--- a/pokecli.py
+++ b/pokecli.py
@@ -24,6 +24,7 @@
 
 Author: tjado <https://github.com/tejado>
 """
+from __future__ import unicode_literals
 
 import argparse
 import codecs
@@ -32,8 +33,6 @@
 import os
 import ssl
 import sys
-reload(sys)
-sys.setdefaultencoding('utf8')
 import time
 import signal
 import string
@@ -128,11 +127,13 @@ def get_commit_hash():
             return f.read()[:8]
 
     try:
-        logger.info('PokemonGO Bot v1.0')
-        logger.info('commit: ' + get_commit_hash())
+        codecs.register(lambda name: codecs.lookup("utf-8") if name == "cp65001" else None)
         sys.stdout = codecs.getwriter('utf8')(sys.stdout)
         sys.stderr = codecs.getwriter('utf8')(sys.stderr)
 
+        logger.info('PokemonGO Bot v1.0')
+        logger.info('commit: ' + get_commit_hash())
+
         config, config_file = init_config()
         if not config:
             return
diff --git a/pokemongo_bot/event_handlers/colored_logging_handler.py b/pokemongo_bot/event_handlers/colored_logging_handler.py
--- a/pokemongo_bot/event_handlers/colored_logging_handler.py
+++ b/pokemongo_bot/event_handlers/colored_logging_handler.py
@@ -2,6 +2,7 @@
 from __future__ import unicode_literals
 
 import logging
+import sys
 
 from pokemongo_bot.event_manager import EventHandler
 
@@ -135,4 +136,4 @@ def handle_event(self, event, sender, level, formatted_msg, data):
             formatted_msg = '[{}] {}'.format(event, formatted_msg)
 
         logger = logging.getLogger(type(sender).__name__)
-        getattr(logger, level)(formatted_msg)
+        getattr(logger, level)(formatted_msg.encode(sys.stdout.encoding, "replace").decode("utf-8"))
diff --git a/pokemongo_bot/event_handlers/logging_handler.py b/pokemongo_bot/event_handlers/logging_handler.py
--- a/pokemongo_bot/event_handlers/logging_handler.py
+++ b/pokemongo_bot/event_handlers/logging_handler.py
@@ -3,6 +3,7 @@
 
 
 import logging
+import sys
 
 from pokemongo_bot.event_manager import EventHandler
 
@@ -19,4 +20,4 @@ def handle_event(self, event, sender, level, formatted_msg, data):
             formatted_msg = '[{}] {}'.format(event, formatted_msg)
 
         logger = logging.getLogger(type(sender).__name__)
-        getattr(logger, level)(formatted_msg)
+        getattr(logger, level)(formatted_msg.encode(sys.stdout.encoding, "replace").decode("utf-8"))


Test patch: