Package for logging to Azure Logs Ingestion API using decorators and regular logging statements.
Project description
Introduction
This logs_ingestion package provides several methods for logging data into Azure Monitor using the Logs Ingestion API.
The following attributes are part of the logging with the coding attribute names between brackets:
- TimeGenerated (time_generated): the datetime the logging entry was created (required)
- Message (message): the message of the log entry (optional)
- Duration (duration): the duration of the function in case the decorator is used (optional)
- Status (status): the status of the system (optional)
- RunId (run_id): the run ID of the flow that is being processed (required)
- Tag (tag): the tag for grouping log entries (required)
The attribute TimeGenerated
is automatically set for you. The RunId
and Tag
are part of the configuration of the logger you need to create and only need to be set once per logger.
Usage
You'll need a logger
to perform the actual logging:
logger: Logger = get_logger(__name__, run_id="42", tag="logger1")
With the logger instantiation you'll also set the RunId
and Tag
to be used in all logging entries as generated through this logger.
The first method for logging information is by using a decorator in your Python code:
@time_and_log(logger=logger, message="bla", status="timed")
def my_function():
pass
Whenever the my_function()
is called a log entry is created with when the function end that automatically includes the duration of the function call. This is a convenient way for monitoring the performance of functions and the possible drift in processing times.
With the message
and status
arguments you can add additional details to the message logged.
The second method is by calling the usual logging lines, for example:
logger.warning(message='testing azure logging', extra={"record": LogsRecord(
status="OK",
message="message",
duration=1.23)})
The arguments are:
message
, speaks for itselfextra
, the extra argument of the standard logging call interface
The extra
argument must be a dictionary with a key of record
which refers to the LogsRecord to use.
Project details
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 logs_ingestion-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f6e6f800df25b60efdb2a0e6e34c7ffd44fc17411eeba41dbf00f3f0ef4b0ffa |
|
MD5 | 6439168613fc5434c03c28ede6d127c7 |
|
BLAKE2b-256 | a3c5b5ba47b33efd8e6df596757c6129d8bdca9d9d5ffecea54332fe69751c8b |