From d0377d8c875faf6126f972546dee174d91e36f2f Mon Sep 17 00:00:00 2001 From: Sam Wedgwood Date: Sat, 17 Mar 2018 12:42:14 +0000 Subject: Added logging to formatter.py (#34) * added logging to formatter.py * Removed unnecessary f string * Added some log.trace() * improved some log.trace() * Removed some stray fullstops --- bot/formatter.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/bot/formatter.py b/bot/formatter.py index 5b75d6a03..0a3360d54 100644 --- a/bot/formatter.py +++ b/bot/formatter.py @@ -60,6 +60,11 @@ class Formatter(HelpFormatter): self._paginator = Paginator(prefix="```py") if isinstance(self.command, Command): + # string used purely to make logs a teensy bit more readable + cog_string = f" from {self.command.cog_name}" if self.command.cog_name else "" + + log.trace(f"Help command is on specific command {self.command.name}{cog_string}.") + # strip the command off bot. and () stripped_command = self.command.name.replace(HELP_PREFIX, "").replace("()", "") @@ -71,6 +76,8 @@ class Formatter(HelpFormatter): # discord.ext.commands.context.Context -> Context arguments = arguments.replace(f"{annotation.__module__}.", "") + log.trace(f"Acquired arguments for command: '{arguments}' ") + # manipulate the argspec to make it valid python when 'calling' the do_ args_no_type_hints = argspec.args for kwarg in argspec.kwonlyargs: @@ -101,6 +108,10 @@ class Formatter(HelpFormatter): self._paginator.add_line(docstring) self._paginator.add_line(invocation) + log.trace(f"Help for {self.command.name}{cog_string} added to paginator.") + + log.debug(f"Help for {self.command.name}{cog_string} generated.") + return self._paginator.pages max_width = self.max_name_size @@ -113,16 +124,23 @@ class Formatter(HelpFormatter): command_list = await self.filter_command_list() data = sorted(command_list, key=category_check) + log.trace(f"Acquired command list and sorted by cog name: {[command.name for command in data]}") + for category, commands in itertools.groupby(data, key=category_check): commands = sorted(commands) if len(commands) > 0: self._paginator.add_line(f"class {category}:") self._add_subcommands_to_page(max_width, commands) + log.trace("Added cog and command names to the paginator.") + self._paginator.add_line() ending_note = self.get_ending_note() # make the ending note appear as comments ending_note = "# "+ending_note.replace("\n", "\n# ") self._paginator.add_line(ending_note) + log.trace("Added ending note to paginator.") + log.debug("General or Cog help generated.") + return self._paginator.pages -- cgit v1.2.3