Automatic trace logging for Python
Actively maintained. Last release 4 weeks ago, commits in 8 of the last 26 weeks. A safe choice.
pip install robocorp-logrobocorp-log
robocorp-log is a library which provides comprehensible logging for Python with a focus on Python automation, where detailed information on what happened and why a failure occurs is of vital importance.
Note: The format of the log is not a part of the API and should not be relied upon as it can change even between minor versions.
Why
Although Python logging is flexible it may be hard to analyze the logging afterwards and visualize it. Also, the format may end up using a big amount of disk space and it may be tedious to add logging calls to all places of interest.
How
robocorp-log improves those aspects by using a structured format which enables using less disk space while also providing a viewer (log.html) for the generated content.
Also, it provides utilities to setup logging so that logging is done automatically without having to explicitly add calls to add content to the logging (although it's still possible to do so when needed).
Usage
It's recommended that robocorp-log is used through robocorp-tasks as robocorp-tasks will configure robocorp-log in a streamlined way, where you just need to worry about marking the entry point method with a @tasks decorator and it'll automatically setup the auto-logging and provide the log result in output/log.html.
Configuring with pyproject.toml
robocorp-tasks takes care of customizing robocorp-log through pyproject.toml.
See the robocorp-tasks project for more information (robocorp-log only provides the core logging structure and different libraries may customize it in different ways).
Although the setup is done through robocorp-tasks, there are still some APIs in robocorp.log which are interesting to use such as:
-
Utility methods to add a log message as
critical,warn,info,debug,exception -
Utility method to add an
htmlmessage (using thehtmlmethod). Note that thehtmlmethod is tested for images with base64 contents in thelog.html, other structures must be manually checked as they can break the layout. Also, keep in mind that the provided html will be sanitized.