commit a2f6f5932fb8ae0736e6c46d2e3ae684376f7aca
parent 7a117f3a470478bdd0464a6abea5be3c47efc877
Author: Matt Brubeck <mbrubeck@limpet.net>
Date: Tue, 22 Dec 2020 17:42:23 -0800
Enable logging by default
Diffstat:
2 files changed, 7 insertions(+), 8 deletions(-)
diff --git a/README.md b/README.md
@@ -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/
diff --git a/src/main.rs b/src/main.rs
@@ -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();
@@ -46,6 +48,7 @@ struct Args {
key_file: String,
hostname: Option<Host>,
language: Option<String>,
+ silent: bool,
}
fn args() -> Result<Args> {
@@ -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())?;
@@ -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,
})
}