feat: log to /tmp by default
This commit is contained in:
@@ -92,6 +92,10 @@ Typing
|
|||||||
If your bindings are not supported, please reach out. \
|
If your bindings are not supported, please reach out. \
|
||||||
We would like to work with you and include additional bindings.
|
We would like to work with you and include additional bindings.
|
||||||
|
|
||||||
|
# Troubleshooting
|
||||||
|
|
||||||
|
Check [here](https://github.com/galister/wlx-overlay-s/wiki/Troubleshooting) for tips.
|
||||||
|
|
||||||
# Known Issues
|
# Known Issues
|
||||||
|
|
||||||
## Auto-Start not working on SteamVR 2.4.4
|
## Auto-Start not working on SteamVR 2.4.4
|
||||||
|
|||||||
61
src/main.rs
61
src/main.rs
@@ -18,7 +18,7 @@ use std::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use flexi_logger::FileSpec;
|
use flexi_logger::{Duplicate, FileSpec, LogSpecification};
|
||||||
|
|
||||||
/// The lightweight desktop overlay for OpenVR and OpenXR
|
/// The lightweight desktop overlay for OpenVR and OpenXR
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
@@ -44,26 +44,15 @@ struct Args {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let args = Args::parse();
|
let mut args = Args::parse();
|
||||||
let maybe_logfile = std::env::var("WLX_LOGFILE").ok();
|
logging_init(&mut args)?;
|
||||||
|
|
||||||
if let Some(ref log_to) = args.log_to.as_ref().or(maybe_logfile.as_ref()) {
|
|
||||||
let file_spec = FileSpec::try_from(PathBuf::from(log_to))?;
|
|
||||||
flexi_logger::Logger::try_with_env_or_str("info")?
|
|
||||||
.log_to_file(file_spec)
|
|
||||||
.duplicate_to_stderr(flexi_logger::Duplicate::Info)
|
|
||||||
.start()?;
|
|
||||||
println!(" ****** Logging to: {} ******", &log_to);
|
|
||||||
println!(" ****** Console logs limited to Info ******");
|
|
||||||
} else {
|
|
||||||
flexi_logger::Logger::try_with_env_or_str("info")?.start()?;
|
|
||||||
}
|
|
||||||
|
|
||||||
log::info!(
|
log::info!(
|
||||||
"Welcome to {} version {}!",
|
"Welcome to {} version {}!",
|
||||||
env!("CARGO_PKG_NAME"),
|
env!("CARGO_PKG_NAME"),
|
||||||
env!("CARGO_PKG_VERSION")
|
env!("CARGO_PKG_VERSION")
|
||||||
);
|
);
|
||||||
|
log::info!("It is {}.", chrono::Local::now().format("%c"));
|
||||||
|
|
||||||
#[cfg(feature = "openvr")]
|
#[cfg(feature = "openvr")]
|
||||||
if args.uninstall {
|
if args.uninstall {
|
||||||
@@ -143,3 +132,45 @@ fn args_get_openxr(_args: &Args) -> bool {
|
|||||||
|
|
||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn logging_init(args: &mut Args) -> anyhow::Result<()> {
|
||||||
|
let log_file = args
|
||||||
|
.log_to
|
||||||
|
.take()
|
||||||
|
.or_else(|| std::env::var("WLX_LOGFILE").ok())
|
||||||
|
.or_else(|| Some("/tmp/wlx.log".to_string()));
|
||||||
|
|
||||||
|
if let Some(log_to) = log_file.filter(|s| !s.is_empty()) {
|
||||||
|
if let Err(e) = file_logging_init(&log_to) {
|
||||||
|
log::error!("Failed to initialize file logging: {}", e);
|
||||||
|
flexi_logger::Logger::try_with_env_or_str("info")?.start()?;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
flexi_logger::Logger::try_with_env_or_str("info")?.start()?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn file_logging_init(log_to: &str) -> anyhow::Result<()> {
|
||||||
|
let file_spec = FileSpec::try_from(PathBuf::from(log_to))?;
|
||||||
|
let log_spec = LogSpecification::env_or_parse("info")?;
|
||||||
|
|
||||||
|
let duplicate = log_spec
|
||||||
|
.module_filters()
|
||||||
|
.iter()
|
||||||
|
.find(|m| m.module_name.is_none())
|
||||||
|
.map(|m| match m.level_filter {
|
||||||
|
log::LevelFilter::Trace => Duplicate::Trace,
|
||||||
|
log::LevelFilter::Debug => Duplicate::Debug,
|
||||||
|
log::LevelFilter::Info => Duplicate::Info,
|
||||||
|
log::LevelFilter::Warn => Duplicate::Warn,
|
||||||
|
_ => Duplicate::Error,
|
||||||
|
});
|
||||||
|
|
||||||
|
flexi_logger::Logger::with(log_spec)
|
||||||
|
.log_to_file(file_spec)
|
||||||
|
.duplicate_to_stderr(duplicate.unwrap_or(Duplicate::Error))
|
||||||
|
.start()?;
|
||||||
|
println!("Logging to: {}", log_to);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user