diff --git a/README.md b/README.md index 850c65e..98b972d 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,12 @@ OPTIONS: -p, --port port to listen to [default: 7791] ``` +You can modify the amount of logging with the `RUST_LOG` parameter: + +For basic application info (default): `RUST_LOG=gitkv=info ./gitkv` +Including incoming HTTP requests: `RUST_LOG=info ./gitkv` +For more information check [env_logger](https://docs.rs/env_logger/*/env_logger/index.html)'s documentation. + ## Security Note that git stores all the content plain so that it's not a good place to store secrets and sensitive information. diff --git a/server/Cargo.toml b/server/Cargo.toml index 3afe4c7..d07c662 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -14,6 +14,8 @@ clap = "^2.32.0" futures = "^0.1.26" serde = "^1.0.89" serde_derive = "^1.0.89" +log = "^0.4.6" +env_logger = "^0.6.1" # When building for musl (ie. a static binary), we opt into the "vendored" # feature flag of openssl-sys which compiles libopenssl statically for us. diff --git a/server/src/main.rs b/server/src/main.rs index 61549d4..67a04a8 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -3,9 +3,15 @@ extern crate clap; #[macro_use] extern crate serde_derive; extern crate actix_web; +#[macro_use] +extern crate log; +extern crate env_logger; + +use log::Level; use actix_web::actix::{Actor, Addr, System}; use actix_web::{http, middleware, server, App, Binary, FromRequest, HttpRequest, Responder}; +use env_logger::Env; use futures::future::Future; use handlers::{CatFile, GitRepos}; use std::path::Path; @@ -16,6 +22,8 @@ const DEFAULT_REPO_ROOT: &str = "./"; const DEFAULT_REFERENCE: &str = "heads/master"; fn main() { + env_logger::from_env(Env::default().default_filter_or("gitkv=info")).init(); + let args = parse_args().get_matches(); let host = args.value_of("host").unwrap_or(DEFAULT_HOST); @@ -43,10 +51,22 @@ pub struct AppState { fn run_server(host: &str, port: &str, repo_root: &Path) { let _sys = System::new("gitkv-server"); - let addr = GitRepos::new(git::load_repos(&repo_root)).start(); + let repos = git::load_repos(&repo_root); + if log_enabled!(Level::Info) { + let keys = repos + .keys() + .map(|key| (*key).clone()) + .collect::>(); + + info!("Loaded Git repos: [{}]", keys.join(", ")) + } + + let addr = GitRepos::new(repos).start(); let listen_address = format!("{}:{}", host, port); + info!("Listening on {}", listen_address); + server::new(move || { App::with_state(AppState { git_repos: addr.clone(),