| Crates.io | graflog |
| lib.rs | graflog |
| version | 1.6.1 |
| created_at | 2025-11-02 17:18:10.890265+00 |
| updated_at | 2025-11-16 10:58:50.87892+00 |
| description | Structured JSON logging for Rust applications optimized for Grafana ingestion |
| homepage | https://github.com/bennekrouf/graflog |
| repository | https://github.com/bennekrouf/graflog |
| max_upload_size | |
| id | 1913351 |
| size | 24,731 |
Structured JSON logging optimized for Grafana ingestion. Clean enum-based configuration.
cargo add graflog
use graflog::{init_logging, app_log, app_span, LogOption};
fn main() {
// Simple logging
init_logging!(&log_path, "payment-service", "api", &[LogOption::Debug]);
// Silent rocket with console disabled
init_logging!(&log_path, "api0", "uploader", &[
LogOption::Debug,
LogOption::RocketOff,
LogOption::NoConsole
]);
// Multiple filters in any order
init_logging!(&log_path, "service", "component", &[
LogOption::ActixWarn,
LogOption::Info,
LogOption::HyperOff
]);
// Custom filter
init_logging!(&log_path, "service", "component", &[
LogOption::Debug,
LogOption::Custom("my_crate::module=warn".to_string())
]);
// Log with automatic service/component tags
app_log!(info, "Server started on port 8080");
app_log!(error, "Database connection failed", error_code = 500);
// Log with custom service/component
app_log!(debug, "user-service", "auth", "Login attempt", user_id = 12345);
// Create spans for distributed tracing
let process_span = app_span!(
"process_payment",
user_id = %user_id,
amount = amount
);
let _enter = process_span.enter();
}
LogOption::TraceLogOption::DebugLogOption::InfoLogOption::WarnLogOption::ErrorLogOption::RocketOff - Turn off rocket logsLogOption::ActixOff / LogOption::ActixWarn - Control actix_web logsLogOption::HyperOff / LogOption::HyperWarn - Control hyper logsLogOption::TokioOff / LogOption::TokioWarn - Control tokio logsLogOption::Console - Enable console output (default)LogOption::NoConsole - Disable console outputLogOption::Custom("target=level".to_string()) - Any custom filterLogs are formatted with consistent fields:
service: Service identifiercomponent: Component within servicetimestamp: RFC3339 formatted timestamplevel: Log level (trace, debug, info, warn, error)Perfect for Grafana Loki queries:
{service="payment-service"} | json | level="error"
{service="auth-service"} | json | component="jwt"
Old syntax:
init_logging!(&log_path, "service", "component", "debug", "rocket::server=off", false);
New syntax:
init_logging!(&log_path, "service", "component", &[
LogOption::Debug,
LogOption::RocketOff,
LogOption::NoConsole
]);