Python module to ease Azure DevOps pipelines logging commands
Project description
Azure DevOps pipelines python logger
Azure pipelines have a feature called Logging commands, which makes it possible to communicate with the Azure pipeline agent.
These logging commands are often used to set a pipeline variable, but can also be used to write formatted logs in the task standard outputs, or write error/warning messages on the pipeline results web page.
For example, writing the following logs to the standard output :
print("##[group]Beginning of a group")
print("##[warning]Warning message")
print("##[error]Error message")
print("##[section]Start of a section")
print("##[debug]Debug text")
print("##[command]Command-line being run")
print("##[endgroup]")
Will render in the task logs like this :
This convenience python module is designed to make formatted logging and error/warning messages in Azure pipelines easier to use.
It uses the python logging system by creating a subclass of logging.LoggerAdapter.
Install
pip install azlog
Usage
First create an AzLogger
from azlog import AzLogger
# Create the logger
logger = AzLogger(__name__)
logger.setLevel(logging.INFO)
The AzLogger adapter will create a python Logger with the name provided as argument.
Internally, AzLogger will create a StreamHandler using an AzFormatter as its formatter
You can also provide your own logger if you need additionnal handlers :
import logging
from azlog import AzLogger
raw_logger = logging.getLogger(__name__)
raw_logger.addHandler(logging.FileHandler('file.log'))
logger = AzLogger(raw_logger)
logger.setLevel(logging.INFO)
You can then use the AzLogger to print formatted log messages to your task output
logger.group("Beginning of a group")
logger.warning("Warning message")
logger.error("Error message")
logger.section("Start of a section")
logger.debug("Debug text")
logger.command("Command-line being run")
logger.endgroup("")
Will render in the task output like this :
Or to raise status messages
logger.issueerror("Issue an error to the pipeline")
logger.issuewarning("Issue a warning to the pipeline")
Will render in the pipeline status page like this :
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file azlog-0.1.1.tar.gz.
File metadata
- Download URL: azlog-0.1.1.tar.gz
- Upload date:
- Size: 2.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
59e38fcd5f0bb5c7a3ba07b817dc865293bc6f812f18a13d535ad808321153dd
|
|
| MD5 |
35b662fd9c9a4bc6d16cf2f4d81a1d69
|
|
| BLAKE2b-256 |
331a36aff6078700ae5ad4b4cf89ebec11970319965801780c897dce96daea3a
|
File details
Details for the file azlog-0.1.1-py3-none-any.whl.
File metadata
- Download URL: azlog-0.1.1-py3-none-any.whl
- Upload date:
- Size: 2.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
71ecb2bbee1d1a5c960c1466bfeb10d8fcf845ef7e82a071190841081222b9b9
|
|
| MD5 |
691ef32473c2aee912fc63d864059588
|
|
| BLAKE2b-256 |
2d84c739526772c7c8fc3dc06e30d15bcb40ca03a2fa9afa07995f733654620d
|