https://github.com/romac/rocket-slog-fairing
Fairing that you can attach to your rocket.rs application to enable use of a slog Logger in your handlers. Fork of https://gitlab.com/pwoolcoc/rocket-slog-fairing
https://github.com/romac/rocket-slog-fairing
Last synced: 5 days ago
JSON representation
Fairing that you can attach to your rocket.rs application to enable use of a slog Logger in your handlers. Fork of https://gitlab.com/pwoolcoc/rocket-slog-fairing
- Host: GitHub
- URL: https://github.com/romac/rocket-slog-fairing
- Owner: romac
- License: gpl-3.0
- Created: 2019-05-22T14:43:30.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-05-22T14:54:50.000Z (about 7 years ago)
- Last Synced: 2025-04-12T14:29:18.430Z (about 1 year ago)
- Language: Rust
- Homepage:
- Size: 22.5 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.adoc
- License: LICENSE
Awesome Lists containing this project
README
= Integrate a slog Logger with your Rocket.rs application
http://pwoolcoc.gitlab.io/rocket-slog-fairing/rocket_slog/index.html[Documentation (master)]
This is a fairing that you can attach to your rocket.rs application to enable use of a slog `Logger` in your
handlers
== Installation (for rocket v0.3)
In your `Cargo.toml`, put the following in the `[dependencies]` section:
----
rocket-slog = "0.3"
----
For pre-2018-edition crates, put the following in your crate root:
----
extern crate rocket_slog;
----
== Installation (for rocket 0.4)
In your `Cargo.toml`, put the following in the `[dependencies]` section:
----
rocket-slog = "0.4.0-rc.2"
----
For pre-2018-edition crates, put the following in your crate root:
----
extern crate rocket_slog;
----
== Example (for rocket 0.3)
Here is an example application that uses the rocket-slog fairing. Note that you should probably disable the builtin
rocket logger unless you want the output from both logging systems.
----
#![feature(plugin)]
#![plugin(rocket_codegen)]
extern crate rocket;
extern crate rocket_slog;
#[macro_use(debug)] extern crate slog;
extern crate sloggers;
use std::error::Error;
use rocket::{Config};
use rocket_slog::{SyncLogger, SlogFairing};
use sloggers::{
Build,
terminal::{
TerminalLoggerBuilder,
Destination,
},
types::Severity,
};
#[get("/")]
fn index(logger: SyncLogger) -> &'static str {
debug!(logger.get(), "THIS IS A CUSTOM MESSAGE");
"hello, world"
}
fn main() -> Result<(), Box> {
let mut builder = TerminalLoggerBuilder::new();
builder.level(Severity::Debug);
builder.destination(Destination::Stderr);
let logger = builder.build()?;
let fairing = SlogFairing::new(logger);
let config = Config::development().unwrap();
rocket::custom(config, false) // disables logging
.attach(fairing)
.mount("/", routes![index])
.launch();
Ok(())
}
----
== Example (for rocket 0.4)
----
#![feature(proc_macro_hygiene, decl_macro)]
#[macro_use] extern crate rocket;
#[macro_use(debug)] extern crate slog;
extern crate rocket_slog;
extern crate sloggers;
use std::error::Error;
use rocket::config::{Config, Environment, LoggingLevel};
use rocket_slog::{SlogFairing, SyncLogger};
use sloggers::{
Build,
terminal::{
TerminalLoggerBuilder,
Destination,
},
types::Severity,
};
#[get("/")]
fn index(log: SyncLogger) -> &'static str {
debug!(log, "some log message");
"Hello world"
}
fn main() -> Result<(), Box> {
let mut builder = TerminalLoggerBuilder::new();
builder.level(Severity::Debug);
builder.destination(Destination::Stderr);
let logger = builder.build()?;
let fairing = SlogFairing::new(logger);
let config = Config::build(Environment::Development)
.log_level(LoggingLevel::Off) // disables logging
.finalize()
.unwrap();
rocket::custom(config)
.mount("/", routes![index])
.attach(fairing)
.launch();
Ok(())
}
----