Skip to content
This repository has been archived by the owner on Sep 26, 2023. It is now read-only.

Commit

Permalink
Add logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Kit committed Apr 15, 2019
1 parent d247e15 commit 518bbf6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ OPTIONS:
-p, --port <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.
Expand Down
2 changes: 2 additions & 0 deletions server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
22 changes: 21 additions & 1 deletion server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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::<Vec<String>>();

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(),
Expand Down

0 comments on commit 518bbf6

Please sign in to comment.