Logging¶
This indipydriver package uses the Python standard library logging module, and emits logs at levels:
ERROR Logs errors including tracebacks from exceptions
WARNING Logs connection status for remote links
INFO Logs informational messages.
DEBUG Logs xml data transmitted and received.
By default, the set level is WARNING, and therefore warning and error logs are sent to stdout. If you want no logs, and you want nothing to be sent to the console, then insert:
import logging
logger = logging.getLogger()
logger.addHandler(logging.NullHandler())
If you would prefer to log to a file, at the top of your script include:
import logging
logger = logging.getLogger()
fh = logging.FileHandler("logfile.log")
logger.addHandler(fh)
To log the xml traffic add the further line:
logger.setLevel(logging.DEBUG)
This leaves you with the flexibility to add any available loghandler (see the Python logging documentation), and to set your own formats if required.
The xml traffic logs generated with the lines above will be those created by the IPyServer class which has attribute debug_enable set to True as default.
This will be the traffic to and from the server to connected clients, however this will miss snooping traffic sent between drivers. To log driver xml traffic you can set the driver.debug_enable attribute to True, and also the IPyServer add_remote and add_exdriver methods have a debug_enable argument which can be used to enable logging of their traffic.
If more than one debug_enable is set to True your logs will get duplicated traffic, so typically you would only have one debug_enable set.
Advanced
The logging.getlogger() command shown above gets the root logger, which gathers all logs generated by all the Python modules in this package. However you can ‘get’ other loggers by specifying module paths, so:
serverlogger = logging.getlogger("indipydriver.ipyserver")
Will get a logs from the ipyserver module.
indipydriver.ipyserver - generates server logs
indipydriver.ipydriver - generates attached driver logs
indipydriver.remote - generates remote connection logs.
You could then add file handlers and set logging levels to each logger separately, giving you the capability to separately record driver and server traffic.