DiscordHandler#

tradeexecutor.cli.discord_handler.DiscordHandler class.

class DiscordHandler[source]#

Bases: Handler

A handler class which writes logging records, appropriately formatted, to a Discord Server using webhooks.

__init__(service_name, webhook_url, colours={None: 2040357, 50: 14362664, 40: 14362664, 30: 16497928, 20: 2196944, 10: 8947848}, emojis={None: ':loudspeaker:', 50: ':x:', 40: ':x:', 30: ':warning:', 20: ':bell:', 10: ':microscope:'}, avatar_url=None, rate_limit_retry=True, embed_line_wrap_threshold=60)[source]#

Initializes the instance - basically setting the formatter to None and the filter list to empty.

Parameters
  • service_name (str) –

  • webhook_url (str) –

Methods

__init__(service_name, webhook_url[, ...])

Initializes the instance - basically setting the formatter to None and the filter list to empty.

acquire()

Acquire the I/O thread lock.

addFilter(filter)

Add the specified filter to this handler.

clip_content(content[, max_len, clip_to_end])

Make sure the text fits to a Discord message.

close()

Tidy up any resources used by the handler.

createLock()

Acquire a thread lock for serializing access to the underlying I/O.

emit(record)

Send a log entry to Discord.

filter(record)

Determine if a record is loggable by consulting all the filters.

flush()

Ensure all logging output has been flushed.

format(record)

Format the specified record.

get_name()

handle(record)

Conditionally emit the specified logging record.

handleError(record)

Handle errors which occur during an emit() call.

release()

Release the I/O thread lock.

removeFilter(filter)

Remove the specified filter from this handler.

setFormatter(fmt)

Set the formatter for this handler.

setLevel(level)

Set the logging level of this handler.

set_name(name)

should_format_as_code_block(record, msg)

Figure out whether we want to use code block formatting in Discord

Attributes

name

__init__(service_name, webhook_url, colours={None: 2040357, 50: 14362664, 40: 14362664, 30: 16497928, 20: 2196944, 10: 8947848}, emojis={None: ':loudspeaker:', 50: ':x:', 40: ':x:', 30: ':warning:', 20: ':bell:', 10: ':microscope:'}, avatar_url=None, rate_limit_retry=True, embed_line_wrap_threshold=60)[source]#

Initializes the instance - basically setting the formatter to None and the filter list to empty.

Parameters
  • service_name (str) –

  • webhook_url (str) –

should_format_as_code_block(record, msg)[source]#

Figure out whether we want to use code block formatting in Discord

Parameters
Return type

bool

clip_content(content, max_len=1900, clip_to_end=True)[source]#

Make sure the text fits to a Discord message.

Discord max message length is 2000 chars.

Parameters

content (str) –

Return type

str

emit(record)[source]#

Send a log entry to Discord.

Parameters

record (LogRecord) –