database.logging

Module Contents

Classes

Logging

Log configuration.

class database.logging.Logging

Log configuration.

Note

There are two logs: a bot log and a guild log.

Bot logs are events that may concern anyone using the bot – module unload, for example.

Guild logs are only contained in the guild and cannot be displayed on other servers the bot is in. An example of this may be an ACL configuration change.

Each Logging object has attribute guild_id representing guilded.Guild and channel_id representing guilded.channel.ChatChannel. They determine where the log should be sent, if one is created.

The scope may only have two values: bot or guild, and it marks the difference between the two types of logs.

level attribute specifies the minimal required log level (INFO, WARNING, …) for the log to be considered active.

module is an optional argument. If None, it determines log level for the whole server: the guild may have general level configured as WARNING, but you want to have more information from that one module that behaves strangely, and set its logging level to INFO, without having to deal with the bot being on INFO level as a whole.

Another advantage is the fact that you can direct logs of the module into different channel from the rest of the application.

The module attribute is only applicable to the guild scope.

Note

You can think of this object as log subscription, or as the minimum requirements for the log to be sent to some Guilded channel.

Command API for this database table is located in the Logging module.

idx
guild_id
channel_id
scope
level
module
static add_bot(guild_id: int, channel_id: int, level: int) Logging

Add log subscription for bot events.

Parameters
  • guild_id – Guild ID of subscription channel.

  • channel_id – Channel ID of subscription channel.

  • level – Minimal logging level to be reported.

Returns

Created bot log subscription.

static get_bot(guild_id: int) Optional[Logging]

Get bot log subscription in given guild.

Parameters

guild_id – Guild ID of subscription channel.

Returns

Bot log subscription or None.

static get_bots(level: int) List[Logging]

Get all bot log subscriptions for at least given level.

Parameters

level – Minimal log level.

Returns

Matching bot log subscriptions.

static remove_bot(guild_id: int) int

Remove bot log subscription in the guild.

Parameters

guild_id – Guild ID of subscription channel.

Returns

Number of deleted bot log subscriptions, always 0 or 1.

static add_guild(guild_id: int, channel_id: int, level: int, module: Optional[str] = None) Logging

Add logging preference.

Parameters
  • guild_id – Guild ID of subscription channel.

  • channel_id – Channel ID of subscription channel.

  • level – Minimal logging level to be reported.

  • module – Module filter or None.

Returns

Created guild log subscription.

static get_guild(guild_id: int, level: int, module: Optional[str] = None) Optional[Logging]

Get active guild logger.

Parameters
  • guild_id – Guild ID.

  • level – Minimal log level.

  • module – Get filter overwrite of guild settings.

Returns

Guild log subscription or None.

If the module isn’t found (i.e. is not set), guild default is used. If the guild doesn’t have set log level either, None is returned and the log won’t get processed and/or sent anywhere.

static remove_guild(guild_id: int, module: Optional[str] = None) int

Remove all log subscriptions of the guild.

Parameters
  • guild_id – Guild ID of subscription channel.

  • module – Module filter or None.

Returns

Number of deleted guild log subscriptions, always 0 or 1.

static get_all(guild_id: int) List[Logging]

Get all log subscriptions in given guild.

Parameters

guild_id – Guild ID of subscription channel.

Returns

All log subscriptions of given guild.