axlogger 0.1.0

A lightweight, configurable request logging middleware for Axum.
Documentation
<h1 align="center">
  <img src="assets/axlog.png" alt="AxLogger Logo" width="40">
  AxLogger
</h1>

[![crates.io](https://img.shields.io/crates/v/axlogger.svg)](https://crates.io/crates/axlogger)
[![docs.rs](https://docs.rs/axlogger/badge.svg)](https://docs.rs/axlogger)
[![CI](https://github.com/aliwert/axlogger/actions/workflows/ci.yml/badge.svg)](https://github.com/aliwert/axlogger/actions/workflows/ci.yml)
[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE-MIT)
[![License: Apache-2.0](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](LICENSE-APACHE)
[![Rust](https://img.shields.io/badge/rust-1.75%2B-orange.svg)](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] | GET | /users/42 | 200 | 0.43ms | 2026-07-04 22:46:35
[MyBackend] | POST | /login | 401 | 1.81ms | 2026-07-04 22:46:38
[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
```

| Option              | Description                                  |
| ------------------- | -------------------------------------------- |
| `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