Logging reference#

trace#

daf.logging.tracing.trace(message: str, level: Union[TraceLEVELS, int] = TraceLEVELS.NORMAL, reason: Optional[str] = None)#
Prints a trace to the console.
This is thread safe.

Changed in version v2.3:

Will only print if the level is lower than the configured (thru run()’s debug parameter max level.

Eg. if the max level is ERROR, then the level parameter needs to be either DEPRECATED or ERROR, else nothing will be printed.

Parameters:
  • message (str) – Trace message.

  • level (TraceLEVELS | int) – Level of the trace. Defaults to TraceLEVELS.NORMAL.

get_logger#

daf.logging.get_logger() LoggerBASE#
Returns:

The selected logging object which is of inherited type from LoggerBASE.

Return type:

LoggerBASE

TraceLEVELS#

enum daf.logging.tracing.TraceLEVELS(value)#

Levels of trace for debug.

See also

trace

Changed in version v2.3: Added DEPRECATION

Member Type:

int

Valid values are as follows:

DEPRECATED = <TraceLEVELS.DEPRECATED: 0>#

Show only deprecation notices.

ERROR = <TraceLEVELS.ERROR: 1>#

Show deprecations and errors.

WARNING = <TraceLEVELS.WARNING: 2>#

Show deprecations, errors, warnings.

NORMAL = <TraceLEVELS.NORMAL: 3>#

Show deprecations, errors, warnings, info messages.

DEBUG = <TraceLEVELS.DEBUG: 4>#

Show deprecations, errors, warnings, info messages, debug messages.

LoggerBASE#

class daf.logging.LoggerBASE(fallback=None)#

New in version v2.2.

The base class for making loggers. This can be used to implement your custom logger as well. This does absolutely nothing, and is here just for demonstration.

Parameters:

fallback (Optional[LoggerBASE]) – The manager to use, in case saving using this manager fails.

async initialize() None#

Initializes self and the fallback

async update(**kwargs)#

Used to update the original parameters.

Parameters:

kwargs (Any) – Keyword arguments of any original parameters.

Raises:
  • TypeError – Invalid keyword argument was passed.

  • Other – Other exceptions raised from .initialize method (if it exists).

LoggerCSV#

class daf.logging.LoggerCSV(path: str, delimiter: str, fallback: Optional[LoggerBASE] = None)#

New in version v2.2.

Logging class for generating .csv file logs. The logs are saved into CSV files and fragmented by guild/user and day (each day, new file for each guild).

Each entry is in the following format:

Timestamp, Guild Type, Guild Name, Guild Snowflake, Message Type, Sent Data, Message Mode (Optional), Channels (Optional), Success Info (Optional)

Parameters:
  • path (str) – Path to the folder where logs will be saved.

  • delimiter (str) – The delimiter between columns to use.

  • fallback (Optional[LoggerBASE]) – The manager to use, in case saving using this manager fails.

Raises:

OSError – Something went wrong at OS level (insufficient permissions?) and fallback failed as well.

async initialize() None#

Initializes self and the fallback

async update(**kwargs)#

Used to update the original parameters.

Parameters:

kwargs (Any) – Keyword arguments of any original parameters.

Raises:
  • TypeError – Invalid keyword argument was passed.

  • Other – Other exceptions raised from .initialize method (if it exists).

LoggerJSON#

class daf.logging.LoggerJSON(path: str, fallback: Optional[LoggerBASE] = None)#

New in version v2.2.

Logging class for generating .json file logs. The logs are saved into JSON files and fragmented by guild/user and day (each day, new file for each guild).

Parameters:
  • path (str) – Path to the folder where logs will be saved.

  • fallback (Optional[LoggerBASE]) – The manager to use, in case saving using this manager fails.

Raises:

OSError – Something went wrong at OS level (insufficient permissions?) and fallback failed as well.

async initialize() None#

Initializes self and the fallback

async update(**kwargs)#

Used to update the original parameters.

Parameters:

kwargs (Any) – Keyword arguments of any original parameters.

Raises:
  • TypeError – Invalid keyword argument was passed.

  • Other – Other exceptions raised from .initialize method (if it exists).

LoggerSQL#

class daf.logging.sql.LoggerSQL(username: Optional[str] = None, password: Optional[str] = None, server: Optional[str] = None, port: Optional[int] = None, database: Optional[str] = None, dialect: Optional[str] = None, fallback: Optional[LoggerBASE] = Ellipsis)#

Used for controlling the SQL database used for message logs.

Parameters:
  • username (Optional[str]) – Username to login to the database with.

  • password (Optional[str]) – Password to use when logging into the database.

  • server (Optional[str]) – Address of the server.

  • port (Optional[int]) – The port of the database server.

  • database (Optional[str]) – Name of the database used for logs.

  • dialect (Optional[str]) – Dialect or database type (SQLite, mssql, )

  • fallback (Optional[LoggerBASE]) – The fallback manager to use in case SQL logging fails. (Default: LoggerJSON (“History”))

Raises:

ValueError – Unsupported dialect (db type).

async initialize() None#

This method initializes the connection to the database, creates the missing tables and fills the lookup tables with types defined by the register_type(lookup_table) function.

Note

This is automatically called when running the daf.

Raises:

Any – from ._begin_engine() from ._create_tables() from ._generate_lookup_values()

async update(**kwargs)#

New in version v2.0.

Used for changing the initialization parameters the object was initialized with.

Warning

Upon updating, the internal state of objects get’s reset, meaning you basically have a brand new created object. It also resets the message objects.

Parameters:

**kwargs (Any) – Custom number of keyword parameters which you want to update, these can be anything that is available during the object creation.

Raises:
  • TypeError – Invalid keyword argument was passed.

  • Other – Raised from .initialize() method.