Setting Up Logging¶
gd.py uses logging module to log different information.
By default, it is required to setup the logging by hand, however, gd.py provides a simple way to set up logging all messages into the console:
import gd
gd.setup_logging()
-
gd.setup_logging(level: int = 10, format_string: Optional[str] = None, stream: Optional[IO] = None, filename: Optional[str] = None) → None[source]¶ Setup logger with
levelandformat_string. Either stream handler forstream, or file handler forfilename.- Parameters
level (
int) – Level to set in the handler.format_string (Optional[
str]) – String to use for formatter. Default isgd.logging.DEFAULT_LOG_FORMAT.stream (Optional[IO]) – Stream to write logs to. If
Noneor not given,sys.stderris used.
If something more specific is required, things can still be simple.
Let’s suppose it is required to write all the warnings/errors and critical
messages into a file, for instance, geometry_dash.log:
import logging
import gd
FORMAT = "[{levelname}] ({name}): {message}"
gd.setup_logging(
level=logging.WARNING, # only warnings/errors/critical will be displayed
format_string=FORMAT, # [LEVEL] (gd.some_module): Some message here.
filename="geometry_dash.log", # file to log into
)
See logging documentation for more information about handling loggers.