Use new ‘—log’ command argument to specify server log level

This commit is contained in:
Tobie Morgan Hitchcock 2022-07-19 13:25:55 +01:00
parent 91b8baff3d
commit e1c6245151
3 changed files with 23 additions and 11 deletions

View file

@ -27,7 +27,7 @@ clean:
.PHONY: serve
serve:
cargo run -- -vvv start --user root --pass root memory
cargo run -- start --log trace --user root --pass root memory
.PHONY: quick
quick:

View file

@ -131,15 +131,7 @@ pub fn init() {
.about(INFO)
.before_help(LOGO)
.disable_version_flag(true)
.arg_required_else_help(true)
.arg(
Arg::new("verbose")
.short('v')
.long("verbose")
.takes_value(false)
.multiple_occurrences(true)
.help("Specify the log output verbosity"),
);
.arg_required_else_help(true);
let setup = setup.subcommand(
Command::new("start")
@ -234,6 +226,16 @@ pub fn init() {
.takes_value(true)
.forbid_empty_values(true)
.help("Path to the private key file for encrypted client connections"),
)
.arg(
Arg::new("log")
.short('l')
.long("log")
.takes_value(true)
.default_value("info")
.forbid_empty_values(true)
.help("Database path used for storing data")
.value_parser(["warn", "info", "debug", "trace", "full"]),
),
);

View file

@ -1,4 +1,5 @@
use super::config;
use super::log;
use crate::cnf::LOGO;
use crate::dbs;
use crate::err::Error;
@ -6,7 +7,16 @@ use crate::net;
#[tokio::main]
pub async fn init(matches: &clap::ArgMatches) -> Result<(), Error> {
// output SurrealDB logo
// Set the default log level
match matches.get_one::<String>("log").map(String::as_str) {
Some("warn") => log::init(0),
Some("info") => log::init(1),
Some("debug") => log::init(2),
Some("trace") => log::init(3),
Some("full") => log::init(4),
_ => unreachable!(),
};
// Output SurrealDB logo
println!("{}", LOGO);
// Setup the cli options
config::init(matches);