Skip to content

Commit

Permalink
Fix UnicodeEncodeError on Windows. (#3043)
Browse files Browse the repository at this point in the history
* Fix UnionEncodeError on Windows when logging unicode emojis or special characters.

* Formatting...
  • Loading branch information
Jerrie-Aries authored Aug 1, 2021
1 parent e794325 commit 3e04dd0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
11 changes: 4 additions & 7 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,9 @@ def hosting_method(self) -> HostingMethod:

def startup(self):
logger.line()
if os.name != "nt":
logger.info("┌┬┐┌─┐┌┬┐┌┬┐┌─┐┬┬")
logger.info("││││ │ │││││├─┤││")
logger.info("┴ ┴└─┘─┴┘┴ ┴┴ ┴┴┴─┘")
else:
logger.info("MODMAIL")
logger.info("┌┬┐┌─┐┌┬┐┌┬┐┌─┐┬┬")
logger.info("││││ │ │││││├─┤││")
logger.info("┴ ┴└─┘─┴┘┴ ┴┴ ┴┴┴─┘")
logger.info("v%s", __version__)
logger.info("Authors: kyb3r, fourjr, Taaku18")
logger.line()
Expand Down Expand Up @@ -659,7 +656,7 @@ async def convert_emoji(self, name: str) -> str:
try:
name = await converter.convert(ctx, name.strip(":"))
except commands.BadArgument as e:
logger.warning("%s is not a valid emoji. %s.", e)
logger.warning("%s is not a valid emoji. %s.", name, e)
raise
return name

Expand Down
2 changes: 2 additions & 0 deletions cogs/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ async def debug(self, ctx):
os.path.dirname(os.path.abspath(__file__)), f"../temp/{log_file_name}.log"
),
"r+",
encoding="utf-8",
) as f:
logs = f.read().strip()

Expand Down Expand Up @@ -448,6 +449,7 @@ async def debug_hastebin(self, ctx):
os.path.dirname(os.path.abspath(__file__)), f"../temp/{log_file_name}.log"
),
"rb+",
encoding="utf-8",
) as f:
logs = BytesIO(f.read().strip())

Expand Down
4 changes: 3 additions & 1 deletion core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ def format(self, record):

def configure_logging(name, level=None):
global ch_debug, log_level
ch_debug = RotatingFileHandler(name, mode="a+", maxBytes=48000, backupCount=1)
ch_debug = RotatingFileHandler(
name, mode="a+", maxBytes=48000, backupCount=1, encoding="utf-8"
)

formatter_debug = FileFormatter(
"%(asctime)s %(name)s[%(lineno)d] - %(levelname)s: %(message)s",
Expand Down

0 comments on commit 3e04dd0

Please sign in to comment.