<h1 align="center">
<img src="assets/axlog.png" alt="AxLogger Logo" width="40">
AxLogger
</h1>
[](https://crates.io/crates/axlogger)
[](https://docs.rs/axlogger)
[](https://github.com/aliwert/axlogger/actions/workflows/ci.yml)
[](LICENSE-MIT)
[](LICENSE-APACHE)
[](https://www.rust-lang.org)
A lightweight, configurable request logging middleware for **Axum**.
Minimal request logging for Axum applications.
---
## Features
- 🚀 Lightweight with minimal overhead
- ⚙️ Configure logger output through `logger_config.toml`
- 🎨 Colored HTTP status codes
- 📝 Human-readable log format
- 🔧 Easy integration using `middleware::from_fn`
- 📦 Works as a standalone library crate
- 💡 Sensible defaults with graceful fallback
---
## Example Output
```text
[MyBackend] | DELETE | /users/5 | 500 | 3.22ms | 2026-07-04 22:46:41
```
Status codes are colorized automatically:
- 🟢 **2xx** — Green
- 🔵 **3xx** — Cyan
- 🟡 **4xx** — Yellow
- 🔴 **5xx** — Red
---
# Installation
## From crates.io
```toml
[dependencies]
axlogger = "0.1"
```
---
## Local Path Dependency
```toml
[dependencies]
axlogger = { path = "../axlogger" }
```
---
## Usage
```rust
use axlogger::{init_logger_config, logger_middleware};
#[tokio::main]
async fn main() {
init_logger_config("logger_config.toml");
let app = Router::new()
.route("/", get(handler))
.layer(axum::middleware::from_fn(logger_middleware));
// ...
}
```
Create a `logger_config.toml` file in your project root.
---
# Configuration
Example configuration:
```toml
[logger]
project_name = "MyBackend"
show_project_name = true
show_method = true
show_path = true
show_status = true
show_duration = true
show_timestamp = true
show_query_string = false
colored = true
```
| `project_name` | Project name shown in logs |
| `show_project_name` | Show or hide project name |
| `show_method` | Show or hide HTTP method |
| `show_path` | Show or hide request path |
| `show_status` | Show or hide status code |
| `show_duration` | Show or hide request duration |
| `show_timestamp` | Show or hide timestamp |
| `show_query_string` | Include query parameters in the request path |
| `colored` | Enable or disable colored output |
---
# Running the Demo
Run the included example server:
```bash
cargo run --example demo
```
Then send a few requests:
```bash
curl http://localhost:3000/
curl http://localhost:3000/users/42
curl http://localhost:3000/error
```
---
# Project Structure
```text
axlogger/
├── Cargo.toml
├── logger_config.toml
├── README.md
├── src/
│ └── lib.rs
└── examples/
└── demo.rs
```
- **src/lib.rs** — Middleware implementation and configuration loader.
- **examples/demo.rs** — Example Axum application demonstrating integration.
---
# Design Goals
AxLogger is intentionally designed to be:
- Small
- Easy to integrate
- Dependency-light
- Beginner-friendly
- Configurable without recompilation
- Suitable for local development and small to medium-sized services
It is **not** intended to replace full-featured observability solutions such as `tracing`, but instead provides a simple request logger for projects where minimal setup is preferred.
---
# Notes
- Configuration is loaded **once** during application startup.
- Restart the server after modifying `logger_config.toml`.
- Invalid or missing configuration files automatically fall back to default values.
- The logger never causes your application to fail because of configuration errors.
---
# Contributing
Contributions, suggestions, and bug reports are always welcome.
Feel free to open an issue or submit a pull request.
---
# License
Licensed under either of the following licenses, at your option:
- MIT License
- Apache License 2.0