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.

Parameters:
  • key (str) – The name of the custom log level.

  • message (str) – The message to log.

  • color (str | None) – The color to use for the log level. Defaults to Fore.MAGENTA.

  • level (int) – The log level. Defaults to logging.INFO.

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 Bot is initialized.

Parameters:
  • name (str) – The name of the logger.

  • log_level (int) – The log level for default log messages logging.INFO.

  • console (bool) – Whether to log to the console. Defaults to True.

  • file (bool | str) – Whether to log to a file. Defaults to False. You can also pass a path to a log file.

  • file_mode (str) – The file mode for the log file. Defaults to w.

  • log_format (str | LogFormat) – The log format. Defaults to LogFormat.default.

  • time_format (str | TimeFormat) – The time format. Defaults to TimeFormat.default.

  • discord_log_level (int) –

    The log level for discord log messages. Defaults to logging.WARNING.

    Note

    For discord log messages, webhook_url is required.

  • webhook_url (str | None) – The discord webhook URL to send logs to. Defaults to None.

  • dc_codeblocks (bool) – Whether to use codeblocks for all Discord log messages. Defaults to True.

  • level_spacing (int) – The length of the log level. If the log level is INFO and the spacing is 8, 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 to auto.

  • 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:

logging.Logger

Example

import logging
import ezcord

colors = {
    logging.DEBUG: "blue",
    logging.INFO: "red",
}

ezcord.set_log(colors=colors)