LoggingΒΆ
The demoutrei.discord package utilizes its own custom logging handler, Logger.
To activate logging, execute your program with the following command:
discord <your_main_file>.py [-d|--debug]
The Logger singleton can be imported and used at your will, if enabled. There are two ways that logs can be made:
Immediate log call
The log is immediately printed.
from discord import Logger
Logger.info("Info log")
Logger.debug("Debug log")
Logger.warn("Warn log")
# Output:
# INFO | Info log
# DEBUG | Debug log
# WARN | Warn log
Context manager
The log prints after it exits the context manager. If an exception is caught otherwise, then the log is neglected and the exception is raised.
from discord import Logger
with Logger.info("Did stuff"):
print("Hello, World!")
# Output:
# "Hello, World!"
# INFO | Did stuff
with Logger.warn("Crazy math"):
print(1 / 0)
# Output:
# ERROR | ZeroDivisionError: ...