Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/de-sh/audit-layer
A tracing Layer that pushes specific log lines to an audit_log over HTTP
https://github.com/de-sh/audit-layer
Last synced: 28 days ago
JSON representation
A tracing Layer that pushes specific log lines to an audit_log over HTTP
- Host: GitHub
- URL: https://github.com/de-sh/audit-layer
- Owner: de-sh
- License: agpl-3.0
- Created: 2024-12-16T09:11:31.000Z (about 1 month ago)
- Default Branch: main
- Last Pushed: 2024-12-16T09:53:01.000Z (about 1 month ago)
- Last Synced: 2024-12-16T10:34:12.178Z (about 1 month ago)
- Language: Rust
- Homepage:
- Size: 14.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# AuditLayer
`AuditLayer` is a Rust library providing a structured logging layer that integrates with the `tracing` ecosystem. This layer captures auditable events(any trace with `audit = true`) 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.```rust
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):
```rust
use tracing::info;info!(
audit = true, // Marks this event as auditable
message = "User login attempt",
user_id = 1234,
success = true,
"Audit log example"
);
```