Skip to content

Commit

Permalink
Enable logging by default
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrubeck committed Dec 23, 2020
1 parent 7a117f3 commit a2f6f59
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,6 @@ All of the command-line arguments are optional. Run `agate --help` to see the d

When a client requests the URL `gemini://example.com/foo/bar`, Agate will respond with the file at `path/to/content/foo/bar`. If there is a directory at that path, Agate will look for a file named `index.gmi` inside that directory.

To enable console logging, set a log level via the `AGATE_LOG` environment variable. Logging is powered by the [env_logger crate](https://crates.io/crates/env_logger):

```
AGATE_LOG=info agate --content path/to/content/
```

[Gemini]: https://gemini.circumlunar.space/
[Rust]: https://www.rust-lang.org/
[home]: gemini://gem.limpet.net/agate/
Expand Down
9 changes: 7 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ use std::{error::Error, ffi::OsStr, fs::File, io::BufReader, marker::Unpin, path
use url::{Host, Url};

fn main() -> Result {
env_logger::Builder::from_env("AGATE_LOG").init();
if !ARGS.silent {
env_logger::Builder::new().parse_filters("info").init();
}
task::block_on(async {
let listener = TcpListener::bind(&ARGS.sock_addr).await?;
let mut incoming = listener.incoming();
Expand Down Expand Up @@ -46,6 +48,7 @@ struct Args {
key_file: String,
hostname: Option<Host>,
language: Option<String>,
silent: bool,
}

fn args() -> Result<Args> {
Expand All @@ -57,7 +60,8 @@ fn args() -> Result<Args> {
opts.optopt("", "addr", "Address to listen on (default 0.0.0.0:1965)", "IP:PORT");
opts.optopt("", "hostname", "Domain name of this Gemini server (optional)", "NAME");
opts.optopt("", "lang", "RFC 4646 Language code(s) for text/gemini documents", "LANG");
opts.optflag("h", "help", "print this help menu");
opts.optflag("s", "silent", "Disable logging output");
opts.optflag("h", "help", "Print this help menu");

let usage = opts.usage(&format!("Usage: {} FILE [options]", &args[0]));
let matches = opts.parse(&args[1..]).map_err(|f| f.to_string())?;
Expand All @@ -74,6 +78,7 @@ fn args() -> Result<Args> {
cert_file: check_path(matches.opt_get_default("cert", "cert.pem".into())?)?,
key_file: check_path(matches.opt_get_default("key", "key.rsa".into())?)?,
language: matches.opt_str("lang"),
silent: matches.opt_present("s"),
hostname,
})
}
Expand Down

0 comments on commit a2f6f59

Please sign in to comment.