Add the ability to wait for a debugger.
This commit is contained in:
parent
98d7512e93
commit
8c843d1dac
@ -16,6 +16,7 @@ pub(crate) struct Args {
|
||||
pub(crate) log_file: Option<PathBuf>,
|
||||
pub(crate) no_buffering: bool,
|
||||
pub(crate) command: Command,
|
||||
pub(crate) wait_dbg: bool,
|
||||
}
|
||||
|
||||
pub(crate) enum Command {
|
||||
@ -51,6 +52,8 @@ FLAGS:
|
||||
--log-file <PATH> Log to the specified file instead of stderr
|
||||
--no-buffering Flush log records to the file immediately
|
||||
|
||||
--wait-dbg Wait until a debugger is attached to
|
||||
|
||||
ENVIRONMENTAL VARIABLES:
|
||||
RA_LOG Set log filter in env_logger format
|
||||
RA_PROFILE Enable hierarchical profiler
|
||||
@ -117,6 +120,7 @@ impl Args {
|
||||
log_file: None,
|
||||
command: Command::Version,
|
||||
no_buffering: false,
|
||||
wait_dbg: false,
|
||||
});
|
||||
}
|
||||
|
||||
@ -134,21 +138,40 @@ impl Args {
|
||||
};
|
||||
let log_file = matches.opt_value_from_str("--log-file")?;
|
||||
let no_buffering = matches.contains("--no-buffering");
|
||||
let wait_dbg = matches.contains("--wait-dbg");
|
||||
|
||||
if matches.contains(["-h", "--help"]) {
|
||||
eprintln!("{}", HELP);
|
||||
return Ok(Args { verbosity, log_file: None, command: Command::Help, no_buffering });
|
||||
return Ok(Args {
|
||||
verbosity,
|
||||
log_file: None,
|
||||
command: Command::Help,
|
||||
no_buffering,
|
||||
wait_dbg,
|
||||
});
|
||||
}
|
||||
|
||||
if matches.contains("--print-config-schema") {
|
||||
return Ok(Args { verbosity, log_file, command: Command::PrintConfigSchema, no_buffering }, );
|
||||
return Ok(Args {
|
||||
verbosity,
|
||||
log_file,
|
||||
command: Command::PrintConfigSchema,
|
||||
no_buffering,
|
||||
wait_dbg,
|
||||
});
|
||||
}
|
||||
|
||||
let subcommand = match matches.subcommand()? {
|
||||
Some(it) => it,
|
||||
None => {
|
||||
finish_args(matches)?;
|
||||
return Ok(Args { verbosity, log_file, command: Command::RunServer, no_buffering });
|
||||
return Ok(Args {
|
||||
verbosity,
|
||||
log_file,
|
||||
command: Command::RunServer,
|
||||
no_buffering,
|
||||
wait_dbg,
|
||||
});
|
||||
}
|
||||
};
|
||||
let command = match subcommand.as_str() {
|
||||
@ -223,11 +246,17 @@ impl Args {
|
||||
},
|
||||
_ => {
|
||||
eprintln!("{}", HELP);
|
||||
return Ok(Args { verbosity, log_file: None, command: Command::Help, no_buffering });
|
||||
return Ok(Args {
|
||||
verbosity,
|
||||
log_file: None,
|
||||
command: Command::Help,
|
||||
no_buffering,
|
||||
wait_dbg,
|
||||
});
|
||||
}
|
||||
};
|
||||
finish_args(matches)?;
|
||||
Ok(Args { verbosity, log_file, command, no_buffering })
|
||||
Ok(Args { verbosity, log_file, command, no_buffering, wait_dbg })
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,7 @@ static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;
|
||||
|
||||
fn main() {
|
||||
if let Err(err) = try_main() {
|
||||
log::error!("Unexpected error: {}", err);
|
||||
eprintln!("{}", err);
|
||||
process::exit(101);
|
||||
}
|
||||
@ -28,6 +29,14 @@ fn main() {
|
||||
|
||||
fn try_main() -> Result<()> {
|
||||
let args = args::Args::parse()?;
|
||||
if args.wait_dbg {
|
||||
#[allow(unused_mut)]
|
||||
let mut d = 4;
|
||||
while d == 4 {
|
||||
d = 4;
|
||||
}
|
||||
}
|
||||
|
||||
setup_logging(args.log_file, args.no_buffering)?;
|
||||
match args.command {
|
||||
args::Command::RunServer => run_server()?,
|
||||
@ -56,7 +65,7 @@ fn try_main() -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn setup_logging(log_file: Option<PathBuf>, flush_file: bool) -> Result<()> {
|
||||
fn setup_logging(log_file: Option<PathBuf>, no_buffering: bool) -> Result<()> {
|
||||
env::set_var("RUST_BACKTRACE", "short");
|
||||
|
||||
let log_file = match log_file {
|
||||
@ -69,7 +78,7 @@ fn setup_logging(log_file: Option<PathBuf>, flush_file: bool) -> Result<()> {
|
||||
None => None,
|
||||
};
|
||||
let filter = env::var("RA_LOG").ok();
|
||||
logger::Logger::new(log_file, flush_file, filter.as_deref()).install();
|
||||
logger::Logger::new(log_file, no_buffering, filter.as_deref()).install();
|
||||
|
||||
tracing_setup::setup_tracing()?;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user