mirror of
https://github.com/YGGverse/agate.git
synced 2026-04-08 20:45:29 +00:00
Enable logging by default
This commit is contained in:
parent
7a117f3a47
commit
a2f6f5932f
2 changed files with 7 additions and 8 deletions
|
|
@ -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.
|
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/
|
[Gemini]: https://gemini.circumlunar.space/
|
||||||
[Rust]: https://www.rust-lang.org/
|
[Rust]: https://www.rust-lang.org/
|
||||||
[home]: gemini://gem.limpet.net/agate/
|
[home]: gemini://gem.limpet.net/agate/
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,9 @@ use std::{error::Error, ffi::OsStr, fs::File, io::BufReader, marker::Unpin, path
|
||||||
use url::{Host, Url};
|
use url::{Host, Url};
|
||||||
|
|
||||||
fn main() -> Result {
|
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 {
|
task::block_on(async {
|
||||||
let listener = TcpListener::bind(&ARGS.sock_addr).await?;
|
let listener = TcpListener::bind(&ARGS.sock_addr).await?;
|
||||||
let mut incoming = listener.incoming();
|
let mut incoming = listener.incoming();
|
||||||
|
|
@ -46,6 +48,7 @@ struct Args {
|
||||||
key_file: String,
|
key_file: String,
|
||||||
hostname: Option<Host>,
|
hostname: Option<Host>,
|
||||||
language: Option<String>,
|
language: Option<String>,
|
||||||
|
silent: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn args() -> Result<Args> {
|
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("", "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("", "hostname", "Domain name of this Gemini server (optional)", "NAME");
|
||||||
opts.optopt("", "lang", "RFC 4646 Language code(s) for text/gemini documents", "LANG");
|
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 usage = opts.usage(&format!("Usage: {} FILE [options]", &args[0]));
|
||||||
let matches = opts.parse(&args[1..]).map_err(|f| f.to_string())?;
|
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())?)?,
|
cert_file: check_path(matches.opt_get_default("cert", "cert.pem".into())?)?,
|
||||||
key_file: check_path(matches.opt_get_default("key", "key.rsa".into())?)?,
|
key_file: check_path(matches.opt_get_default("key", "key.rsa".into())?)?,
|
||||||
language: matches.opt_str("lang"),
|
language: matches.opt_str("lang"),
|
||||||
|
silent: matches.opt_present("s"),
|
||||||
hostname,
|
hostname,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue