| Crates.io | audit-layer |
| lib.rs | audit-layer |
| version | 0.1.0 |
| created_at | 2024-12-16 09:53:21.603908+00 |
| updated_at | 2024-12-16 09:53:21.603908+00 |
| description | A tracing Layer that pushes specific log lines to an audit_log over HTTP |
| homepage | |
| repository | https://github.com/de-sh/audit-layer |
| max_upload_size | |
| id | 1484823 |
| size | 86,884 |
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
tracing: Automatically logs auditable events from your application's spans and events.reqwest client.Creating a subscriber with AuditLayer
To use AuditLayer, initialize it with the following parameters:
use audit_layer::AuditLayer;
use tracing_subscriber::Registry;
use tracing_subscriber::layer::SubscriberExt;
use tokio::runtime::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 = Handle::current();
let audit_layer = AuditLayer::new(
"https://logger-endpoint".to_string(),
"logger-username".to_string(),
"logger-password".to_string(),
runtime_handle,
);
let subscriber = Registry::default().with(audit_layer);
tracing::subscriber::set_global_default(subscriber)
.expect("Failed to set global subscriber");
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 tracing::info;
info!(
audit = true, // Marks this event as auditable
message = "User login attempt",
user_id = 1234,
success = true,
"Audit log example"
);