Discord message logger как установить
A custom message logger to Discord for Python 3. This project was inspired from winston-discord-transport for NodeJS and built using discord-webhook, which offers an easy interface for constructing and sending messages through a Discord webhook.
If you are looking for a Slack alternative, please check python-slack-logger.
Install
Install via pip: pip install discord-logger
Basic Usage
Configure various options
There are numerous configurations available to customise the bot.
Emojis inbuilt! 😃
An appropriate emoji is automatically added before the title depending on the level .
Following is the map between level and the emoji added.
- default = :loudspeaker: 📢
- error = :x: ❌
- warn = :warning: ⚠️
- info = :bell: 🔔
- verbose = :mega: 📣
- debug = :microscope: 🔬
- success = :rocket: 🚀
Examples
Set Service Name, Icon and Environment for easy identification
You can configure the log message with service name, icon and environment for easy identification. The Host field which is the hostname of the server is automatically added for every message.
You can even send any meta information like the data in the variables, module names, metrics etc with the metadata field while constructing the message. These data should be passed as a dictionary.
Send messages without Hostname
In case you do not want the hostname to be displayed in the message, disable it by setting "display_hostname": False in the options as follows.
Send messages with different log-levels
The log-level indicates the importance of the message. It changes the color of the discord message in particular. Currently supported levels are,
The log-level can be set during construction of the message like through the parameter level .
If the parameter isn't provided, it'll be set to the one given in default_level . Any invalid input would be ignored and the log-level would be automatically be set to default .
Any complicated nested dictionary can be passed to the metadata field and the message gets forrmatted accordingly for easy reading.
Send complete error traceback
The error field can contain any error message. It will be automatically be formatted in the final message. For example, you can send a complete traceback of an error message to debug faster!
Читайте также: