Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/elmarx/actix-slog
structured logging for actix-web
https://github.com/elmarx/actix-slog
actix-web logging rust slog
Last synced: 5 days ago
JSON representation
structured logging for actix-web
- Host: GitHub
- URL: https://github.com/elmarx/actix-slog
- Owner: elmarx
- License: apache-2.0
- Created: 2020-07-06T08:20:18.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-02-27T01:06:37.000Z (over 1 year ago)
- Last Synced: 2024-08-08T22:53:29.136Z (3 months ago)
- Topics: actix-web, logging, rust, slog
- Language: Rust
- Homepage:
- Size: 15.6 KB
- Stars: 8
- Watchers: 2
- Forks: 6
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
[![Rust build](https://github.com/elmarx/actix-slog/workflows/Rust/badge.svg)](https://github.com/elmarx/actix-slog/actions?query=workflow%3ARust) [![crates.io badge](https://img.shields.io/crates/v/actix-slog.svg)](https://crates.io/crates/actix-slog) [![docs.rs badge](https://docs.rs/actix-slog/badge.svg)](https://docs.rs/actix-slog)
# Structured (access-) logging for actix-web
Provides a [middleware](https://docs.rs/actix-web/2.0.0/actix_web/struct.App.html#method.wrap) (`StructuredLogger`),
similar to [actix_web::middleware:Logger](https://docs.rs/actix-web/2.0.0/actix_web/middleware/struct.Logger.html),
except that it uses [slog](https://crates.io/crates/slog) and thus enables JSON-formatted logging (via [slog-json](https://crates.io/crates/slog-json)).Of course [slog's compact terminal output](https://github.com/slog-rs/slog#terminal-output-example) is a nice add-on,
even if you're just out for JSON-logging.## Usage
See [server_json](examples/server_compact.rs) and [server_compact](examples/server_compact.rs) for working examples.
```rust
let logger: slog::Logger = unimplemented!();HttpServer::new(move || {
App::new()
.wrap(
StructuredLogger::new(logger.new(o!("log_type" => "access"))),
)
})
.bind("[::1]:8080")
```