labrad / pylabrad

python interface for labrad
51 stars 31 forks source link

Created new module labrad.logging to unify and streamline logging process #394

Open clayton-ho opened 2 years ago

clayton-ho commented 2 years ago

This PR completely moves logging from twisted.python.log to labrad.logging module that builds on top of the logging module in the python standard library. This reduces the dependency on twisted, especially its logging modules, which have been legacy for some time. Additionally, since much of the node configuration in node/init.py was for setting up logging, the CLI interface has been moved from twisted.python.usage.Options to the more well-supported and user-friendly argparse module, also from the python standard library.

Setup of a logger can now be done using a call to labrad.logging.setupLogging, which returns a logger configured for the caller object. Problems with duplicate and unwanted logs (which are common nuisances when using multiple modules which separately do logging) are guarded against by ensuring that any log handlers are only set once.

Previously, print statements were diverted to the logger, and log output would in turn be displayed in stdout - this feature is maintained. Logging to logfiles and syslog (both RFC5424 and RFC3164) are supported, with RFC5424 syslog support enabled by adding another dependency (rfc5424-logging-handler). The addition of RFC5424 support allows the use of most standard log management systems, such as Prometheus or Grafana Loki.

Hopefully, logging should now be more robust and usable, such that users can easily implement it in their own classes (e.g. GUI clients, experiment classes).