AuditLayer
AuditLayer
is a Rust library providing a structured logging layer that integrates with the tracing
ecosystem. This layer captures auditable events and sends them to a specified HTTP endpoint, supporting centralized logging and monitoring systems.
Features
- Seamless integration with
tracing
: Automatically logs auditable events from your application's spans and events. - HTTP Delivery: Pushes logs over HTTP using the
reqwest
client. - Flexible Configuration: Easily specify log endpoint, credentials, and runtime configuration.
- Structured Data: Captures and sends event metadata as JSON.
Usage
Creating a subscriber with AuditLayer
To use AuditLayer, initialize it with the following parameters:
- log_endpoint - The HTTP endpoint where logs will be sent.
- username - Username for basic authentication.
- password - Password for basic authentication.
- runtime_handle - A Tokio runtime handle for spawning the HTTP delivery task.
use AuditLayer;
use Registry;
use SubscriberExt;
use Handle;
// Get handle to the current tokio runtime,
// NOTE: ensure this is done from within a tokio runtime else it will fail
let runtime_handle = current;
let audit_layer = new;
let subscriber = default.with;
set_global_default
.expect;
After the subscriber has been setup, you will be able to witness its working as follows(logs should be received by the HTTP server):
use info;
info!;