Logging¶
The indipydriver and indipyserver packages use 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. If you want no logs, and you want nothing to be sent to the console, then at the top of your script 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()
handler = logging.FileHandler("logfile.log")
logger.addHandler(handler)
To log the xml traffic add the further line:
logger.setLevel(logging.DEBUG)
You would also need to set debug_enable on your driver:
driver.debug_enable = True
And if adding remote connections or executable drivers you would set debug_enable to True when adding them.
This leaves you with the flexibility to add any available loghandler (see the Python logging documentation), and to set your own formats if required.
Advanced
The logging.getlogger() command shown above gets the root logger, which gathers all logs generated by all the Python modules in your package. However you can ‘get’ other loggers by specifying module paths, so:
driverlogger = logging.getlogger("indipydriver.ipydriver")
indipydriver.ipydriver - generates driver logs.
indipyserver.exdriver - generates executable driver logs.
indipyserver.remote - generates remote connection logs.
indipyserver.ipyserver - generates server connection logs.
You could then add file handlers and set logging levels to each logger separately.