Skip to content

Commit 3e04dd0

Browse files
authored
Fix UnicodeEncodeError on Windows. (#3043)
* Fix UnionEncodeError on Windows when logging unicode emojis or special characters. * Formatting...
1 parent e794325 commit 3e04dd0

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

bot.py

+4-7
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,9 @@ def hosting_method(self) -> HostingMethod:
122122

123123
def startup(self):
124124
logger.line()
125-
if os.name != "nt":
126-
logger.info("┌┬┐┌─┐┌┬┐┌┬┐┌─┐┬┬")
127-
logger.info("││││ │ │││││├─┤││")
128-
logger.info("┴ ┴└─┘─┴┘┴ ┴┴ ┴┴┴─┘")
129-
else:
130-
logger.info("MODMAIL")
125+
logger.info("┌┬┐┌─┐┌┬┐┌┬┐┌─┐┬┬")
126+
logger.info("││││ │ │││││├─┤││")
127+
logger.info("┴ ┴└─┘─┴┘┴ ┴┴ ┴┴┴─┘")
131128
logger.info("v%s", __version__)
132129
logger.info("Authors: kyb3r, fourjr, Taaku18")
133130
logger.line()
@@ -659,7 +656,7 @@ async def convert_emoji(self, name: str) -> str:
659656
try:
660657
name = await converter.convert(ctx, name.strip(":"))
661658
except commands.BadArgument as e:
662-
logger.warning("%s is not a valid emoji. %s.", e)
659+
logger.warning("%s is not a valid emoji. %s.", name, e)
663660
raise
664661
return name
665662

cogs/utility.py

+2
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ async def debug(self, ctx):
393393
os.path.dirname(os.path.abspath(__file__)), f"../temp/{log_file_name}.log"
394394
),
395395
"r+",
396+
encoding="utf-8",
396397
) as f:
397398
logs = f.read().strip()
398399

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

core/models.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,9 @@ def format(self, record):
127127

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

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

0 commit comments

Comments
 (0)