Skip to main content

discord-lumberjack

A Python logging handler which sends its logs to a Discord Channel or Webhook.

Documentation

You can find the documentation here.

Installation

To install this python module, run the following command

$ pip install discord-lumberjack

Handlers

This python module provides several logging handlers (located in the discord_lumberjack.handlers module) which will send the logs it recieves to a Discord webhook, server channel, or DM channel.

The available handlers are:

  • DiscordChannelHandler - Uses a bot token and a channel ID to send logs to the given channel from the given bot.
  • DiscordDMHandler - Uses a bot token and a user ID to send logs to the given user from the given bot.
  • DiscordWebhookHandler - Uses a webhook URL to send the logs to.
  • DiscordHandler - This is the base class for the other three. You probably don't want to use this unless you're creating your own fancy handler.

Message Creators

In order to send nice looking messages, there are a few message creators available (located in the discord_lumberjack.message_creators module). These are responsible for converting a logging.LogRecord into a message structure that will be sent to Discord's API.

The message creators provided currently will split extremely long messages into several in order to fit within Discord's message limits. If you decide to create your own one, keep that in mind too.

The available message creators are:

  • BasicMessageCreator - This is a simple message creator which will use the handler's set formatter to send the message as plain text. By default, the message will be formatted in monospace, but this can be disabled via the constructor.
  • EmbedMessageCreator - This message creator will create a fancy-looking embed message from the log record. It will ignore the handler's formatter.

Usage

The easiest way to get started is to create a webhook and use that, but if you're using this to log a Discord bot, you can use it's token directly, without needing to create webhooks.

Import

First, you should import the handlers you want to use. For this example, we'll assume we have a Discord bot and we'd like to use it to log every message to a channel and also to send errors to a DM.

We'll be using the DiscordChannelHandler to send all messages of level INFO and above to the channel and DiscordDMHandler to send messages of level ERROR and above to a DM.

from discord_lumberjack.handlers import DiscordChannelHandler, DiscordDMHandler

Basic Setup

You should really read the documentation for the logging module to learn how to set up your logging, but here's a quick snippet to get you started.

import logging
logging.basicConfig(
	level=logging.INFO,
	handlers=[
		DiscordChannelHandler(token=my_bot_token, channel_id=my_channel_id),
		DiscordDMHandler(token=my_bot_token, user_id=my_user_id, level=logging.ERROR),
	]
)

Once you've set up your logging, you can start logging messages like this:

logging.info("This is an informative message that will be sent to the channel.")
logging.error("This is an error, so it will also be sent to the DM.")

Metadata

Release files for discord-lumberjack 1.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for discord-lumberjack 1.1.3
File Size Uploaded
discord-lumberjack-1.1.3.tar.gz 25.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for discord-lumberjack 1.1.3
File Interpreter ABI Platform
discord_lumberjack-1.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 56.1 kB

Release files / discord-lumberjack-1.1.3.tar.gz

Download URL discord-lumberjack-1.1.3.tar.gz
Size 25.9 kB
Tags Source
SHA-256 checksum
How to use checksums
5a2f4194ee5f733950c37141c536b1d6bd0395267f9287c9063a4c4517760713
BLAKE2b-256 checksum
How to use checksums
650142d7d8d0c543bbbebc98e097d699c1a4c25e9e569ef981c499700168251b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.8 CPython/3.8.12 Linux/5.13.0-1025-azure

Release files / discord_lumberjack-1.1.3-py3-none-any.whl

Download URL discord_lumberjack-1.1.3-py3-none-any.whl
Size 30.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
796f9888fb55722ca43a1e86be05ca83b4a40b94f7e5ec212df525d7ac51a0bd
BLAKE2b-256 checksum
How to use checksums
637b22c3dd30612cd4195c8072a05bea90a675241a8b5d2763ed60662bb4f107
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.8 CPython/3.8.12 Linux/5.13.0-1025-azure

Release history Release notifications | RSS feed

This release

1.1.3 This release

2 release files

1.1.2

2 release files

1.1.0

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page