Skip to content

Instantly share code, notes, and snippets.

@ian-p-cooke
Last active September 6, 2018 11:40
Show Gist options
  • Save ian-p-cooke/67b034c43e1047f71abd243ff0007075 to your computer and use it in GitHub Desktop.
Save ian-p-cooke/67b034c43e1047f71abd243ff0007075 to your computer and use it in GitHub Desktop.
enabling crate level logging not working for actix-web
extern crate actix_web;
extern crate slog_envlogger;
use actix_web::actix;
use actix_web::fs::NamedFile;
use actix_web::middleware;
use actix_web::HttpRequest;
use actix_web::Result;
use actix_web::{server, App};
pub fn path(_req: &HttpRequest) -> Result<NamedFile> {
Ok(NamedFile::open("index.html")?)
}
fn main() -> std::result::Result<(), Box<std::error::Error>> {
std::env::set_var("RUST_LOG", "info"); // works
//std::env::set_var("RUST_LOG", "actix_web=info"); //doesn't work
let _guard = slog_envlogger::init()?;
let sys = actix::System::new("test");
let addr = "0.0.0.0:3276";
server::new(|| {
App::new()
.middleware(middleware::Logger::default())
.resource("/", |r| r.f(path))
}).bind(addr)
.expect(&format!("could not bind to {}", addr))
.start();
let _ = sys.run();
Ok(())
}
@ian-p-cooke
Copy link
Author

should log

Sep 06 06:36:07.536 INFO Starting 16 http workers
Sep 06 06:36:07.545 INFO Starting server on http://0.0.0.0:3276

in either case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment