Debugging and logging
By default the payi library logs to logging.getLogger("payi.instrument") at level WARN. You can configure logging in the following ways:
Change the log level
The following example reconfigures the default "payi.instrument" logger to log at level DEBUG to the console.
import logging
logger = logging.getLogger("payi.instrument")
logger.setLevel(logging.DEBUG)
# Create a console handler and set the handler's level to DEBUG
console_handler = logging.StreamHandler()
console_handler.setLevel(logging.DEBUG)
# Create and set a formatter
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
console_handler.setFormatter(formatter)
# Add the console handler to the logger
logger.addHandler(console_handler)NOTE: the payi library is very verbose at DEBUG level, it is recommended only to log at this level locally and in preproduction environments.
Configure a custom logger
You may already have a logger in your agent to which the payi library can also log to. Specify the logger parameter when calling payi_instrument()
from payi.lib.instrument import payi_instrument
import logging
payi_instrument(logger=logging.getLogger("your_custom_logger")Updated about 2 hours ago