-
Notifications
You must be signed in to change notification settings - Fork 20
PlaygroundLoggingQuickstart
If you have noticed already, asyncio
can be hard to debug. Exception messages can get swallowed and the program just keeps running. I have implemented a fairly powerful logging system into Playground that can also provide asyncio
debugging info as well. Here is a quick start to turning it on, using it, and reading the data.
The easiest way to enable playground logging is with the following code:
from playground.common.logging import EnablePresetLogging, PRESET_DEBUG
EnablePresetLogging(PRESET_DEBUG)
This will turn on a significant amount of Playground debug messages both to the screen and to a file in your .playground/logging
directory. You will almost certainly need to turn this off later to keep your screen readable, but it's a good way to debug in the beginning. These messages will also include asyncio
debug messages if asyncio
debugging is turned on. Debugging is turned on with the following code:
loop = asyncio.get_event_loop()
loop.set_debug(enabled=True)
You can get rid of the messages on screen but still send them to log files with using PRESET_QUIET. It still logs most Playground messages, but not Asyncio
and not to the screen.
You can incorporate your own debug and logging messages into Playground's system. You might want to do this when you want to trace data moving through your various layers (e.g., seeing data pass from reliable to secure etc).
Playground's logging piggy-backs on Python's default logging. The only requirement is that the logger name begin with playground.
. If you're familiar with Python logging, a typical way to put logging into a Python file is like this:
import logging
logger = logging.getLogger(__name__)
logger.debug("Debug message")
This is helpful for recognizing different logging messages from different files.
You can still use this pattern, just prefix your logger name with playground.
and maybe another prefix to differentiate your code. Suppose that you're part of a team "haxorrulz"
import logging
logger = logging.getLogger("playground.haxorrulz."+__name__)
logger.debug("Debug message")
Now all of the log messages from this file will show up in playground logs with the name of the file and the haxorrulz prefix. You can see an example of this in the passthrough sample code that's in the class github. If you use the passthrough layer with the echo test (which turns on the verbose logging) you will see the passthrough layer's logging messages in the output.