Package: discord-webhook-logging
Discord webhook loggingSimplelogginghandler and formatter for sending larger logs to discord channels.InstallationPackage can be installed via pip.pip install discord-webhook-loggingUsageimportloggingfromdiscord_webhook_loggingimportDiscordWebhookHandlerlogger=logging.getLogger(__name__)logger.setLevel(logging.DEBUG)handler=DiscordWebhookHandler(webhook_url='<your webhook url>')logger.addHandler(handler)ExamplesHere are some basic examples to demonstrate how this package works.Example of all log levelsPython:logger.debug('This is debug message')logger.info('This is info message')logger.warning('This is warning message')logger.error('This is error message')logger.critical('This is critical message')Discord:===│This is debug message+  │This is info messageW  │This is warning message-  │This is error message-!!│This is critical messageFlushing buffered messagesDiscordWebhookHandler by default buffers messages, so it can send more lines as single messasge. Buffer can store 1989 due to Discords message length limits. It is automatically flushed when there is not enogh space for next message. You can also manualy flush the buffer by callinglogger.flush().Buffer is also automatically flushed right before the app exits.Python:logger.debug('This is debug message')logger.info('This is info message')logger.flush()# All messages in buffer are sentlogger.warning('This is warning message')logger.error('This is error message')logger.critical('This is critical message')# As you can see we do not need to use flush at the end of program.# Remaining buffered messages are automatically flushed before the app exits.Discord:You will see two messages in Discord insted of one like in example above.===│This is debug message+  │This is info messageW  │This is warning message-  │This is error message-!!│This is critical messageIf you want, you can set to flush buffer automatically after every message. However, I do not recommend doing it, due to Discords API rate limits.
You can enable this by settingauto_flush=Truewhile creating the handler.handler = DiscordWebhookHandler(webhook_url='<your webhook url>', auto_flush=True)In this case, after every message, handler sends message to discord channel.Python:logger.debug('This is debug message')logger.info('This is info message')logger.warning('This is warning message')Discord:===│This is debug message+  │This is info messageW  │This is warning messageMulti line logIf single log string contains multiple lines, it is highlighted with "├" character from 2nd line and last line is highlighted with "└"Python:logger.error('1st line\nnext line\n3rd line\nlast line')Discord:-  │1st line
-  ├next line
-  ├3rd line
-  └last lineLong messagesDiscord supports sending messages up to 2000 characters. If longer string is passed into logger, DiscordWebhookFormatter automatically splits message into shorter parts to fit discords 2000 character limt.
If the line was split, it is highlighted with "↳" character.Python:logger.info('0'*2000+'1'*50)Discord:+  │000000000000000000000000000 ... zeroes contiues up to message length limitAnd in the next message remaining text from the same log line+  ↳00000000000000011111111111111111111111111111111111111111111111111