Automatic trace logging for Python
Project description
robocorp-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 current version is still alpha and it's expected that its internal format and APIs may change.
Why
Although the python logging is flexible it may be hard to analyze the logging afterwards and visually analyze 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).
Installation
Install with:
pip install robocorp-log
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
.
robocorp-tasks
also takes care of customizing robocorp-log
through pyproject.toml
.
See robocorp-tasks
for more information.
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
,exception
(note that it's possible to embed html by passinghtml=True
in those methods, so, things as screenshots can be directly embedded into the log). -
Supressing logging through
suppress_variables
,suppress_methods
,suppress
. -
Hiding sensitive data (automatically based on variable or argument names with names registered in
add_sensitive_variable_name
andadd_sensitive_variable_name_pattern
) or by passing the value to be hidden tohide_from_output
.
Caveats
The auto import mode is done by having a pre-import hook which will change the AST at runtime. This mostly works, but there are a couple of caveats to keep in mind:
-
Debuggers may end up stepping into the
robocorp-log
code in many places even if such code isn't in the source code (you may want to configure the debugger you're using to skip calls intorobocorp.log
as that's usually just an implementation detail). -
The logging needs to be fully setup prior to importing any module that should be automatically logged.
-
async
andawait
are not currently well supported (although it's already in the plans).
Dealing with sensitive data in the logs
Internal structure
License: Apache 2.0
Copyright: Robocorp Technologies, Inc.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for robocorp_log-0.0.15-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4db0a63ac94c1e7ea45d165f5900f467284dda4f2b5e4638b36786608074a78b |
|
MD5 | 9db93ee3de0a6eec651955be5b714abd |
|
BLAKE2b-256 | 9d6000070ec0588be54c0461b6ba7a313baaab16353483d380fedbbf95106384 |