Package rpa_logger
A simple python package for logging robotic process automation (RPA) progress.
Usage
The rpa_logger
package is used to log tasks done by RPA or similar script. This is to communicate to the user what tasks are in progress and what tasks have been completed.
Getting started
The logging is done via Logger
class. It provides Logger.start_task()
and Logger.finish_task()
methods for starting and finishing tasks, respectively. An simple hello world case could be examples/hello_world.py
:
from time import sleep
from rpa_logger import Logger
l = Logger()
key = l.start_task('Hello world!')
# Sleep 2 seconds to display the progress spinner
sleep(2)
l.finish_task('SUCCESS', key=key)
l.finish_suite()
When finishing the task, task must be assigned an status. The status can be any string. The status is used to determine the status indicator for the task, for example ✓
or ✗
. This is done, by default, by the get_indicator()
function.
For short tasks, Logger.start_task()
can be omitted. In this case task description should be given as parameter to the Logger.finish_task()
method. Alternatively, Logger.log_task()
, an alias for finish_task, can be used in this case.
If task was started with Logger.start_task()
, it must be stopped with Logger.finish_task()
to stop printing the progress spinner.
The tasks are indentified with keys. Keys are either provided as parameter when starting the task or, if the key
parameter is omitted, new uuid
is automatically generated. In both cases, the key used to identify the started task is returned by the Logger.start_task()
method. A key can be anything that can be used as a dict key
.
After all tasks to be logged have finished, Logger.finish_suite()
can be used to finish the TaskSuite
instance automatically created by the Logger
. This sets the TaskSuite.finished
and TaskSuite.status
variables.
Title and summary
In addition to logging tasks, the Logger
provides Logger.title()
and Logger.summary()
methods for printing title and summary for the RPA process, respectively. Example usage of these methods is provided in examples/title_and_summary.py
:
from rpa_logger import Logger
l = Logger()
l.title(
'Demonstrate title and summary usage',
'Print title, log tasks with different statuses, and print summary')
for status in ['SUCCESS', 'IGNORED', 'FAILURE', 'ERROR', 'SKIPPED', 'UNKNOWN']:
l.log_task(status, f'Demonstrate {status.lower()} status')
l.finish_suite()
# Summary returns number of non-ok tasks. Use that as exit code.
code = l.summary()
exit(code)
Expand source code
'''A simple python package for logging robotic process automation (RPA)
progress.
.. include:: ./usage.md
'''
from ._version import __version__
from .logger import Logger
Sub-modules
rpa_logger.logger
-
The main interface for using the
rpa_logger
package … rpa_logger.task
-
Constants and helpers for describing RPA tasks and their status.
rpa_logger.utils
-
Utilities to make
rpa_logger
usage easier.