pub(crate) log_file: Option<PathBuf>,
pub(crate) no_buffering: bool,
pub(crate) command: Command,
+ pub(crate) wait_dbg: bool,
}
pub(crate) enum Command {
--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
log_file: None,
command: Command::Version,
no_buffering: false,
+ wait_dbg: false,
});
}
};
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() {
},
_ => {
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 })
}
}
fn main() {
if let Err(err) = try_main() {
+ log::error!("Unexpected error: {}", err);
eprintln!("{}", err);
process::exit(101);
}
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()?,
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 {
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()?;