Logs¶
Some logging utilities that are used for bot logs.
- ezcord.logs.custom_log(key, message, *, color='\\x1b[35m', level=20)[source]¶
Log a message with a custom log level.
- ezcord.logs.set_log(name='ezcord', log_level=20, *, console=True, file=False, file_mode='w', log_format=LogFormat.default, time_format=TimeFormat.time, discord_log_level=30, webhook_url=None, dc_codeblocks=True, level_spacing=8, space_mode='auto', colors=None)[source]¶
Creates a logger. If this logger already exists, it will return the existing logger.
This should be called before
Botis initialized.- Parameters:
name (
str) – The name of the logger.log_level (
int) – The log level for default log messageslogging.INFO.console (
bool) – Whether to log to the console. Defaults toTrue.file (
bool|str) – Whether to log to a file. Defaults toFalse. You can also pass a path to a log file.file_mode (
str) – The file mode for the log file. Defaults tow.log_format (
str|LogFormat) – The log format. Defaults toLogFormat.default.time_format (
str|TimeFormat) – The time format. Defaults toTimeFormat.default.discord_log_level (
int) –The log level for discord log messages. Defaults to
logging.WARNING.Note
For discord log messages,
webhook_urlis required.webhook_url (
str|None) – The discord webhook URL to send logs to. Defaults toNone.dc_codeblocks (
bool) – Whether to use codeblocks for all Discord log messages. Defaults toTrue.level_spacing (
int) – The length of the log level. If the log level isINFOand the spacing is8, the log level will be filled with 4 additional spaces, so that all log levels are 8 characters long.space_mode (
Literal['auto','always','never']) – Choose when to add spacing to the log level. Defaults toauto.colors (
dict[int,str] |str|None) – A dictionary of log levels and their corresponding colors. If only one color is given, all log levels will be colored with that color.
- Return type:
Example
import logging import ezcord colors = { logging.DEBUG: "blue", logging.INFO: "red", } ezcord.set_log(colors=colors)