feat: pop-launcher plugin logging when RUST_LOG=debug enables it
This commit is contained in:
parent
55864b78e2
commit
95e96c8958
3 changed files with 31 additions and 7 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -1152,6 +1152,7 @@ dependencies = [
|
|||
name = "pop-launcher-bin"
|
||||
version = "1.2.0"
|
||||
dependencies = [
|
||||
"dirs 4.0.0",
|
||||
"pop-launcher-plugins",
|
||||
"pop-launcher-service",
|
||||
"tokio",
|
||||
|
|
|
|||
|
|
@ -12,7 +12,8 @@ pop-launcher-plugins = { path = "../plugins" }
|
|||
pop-launcher-service = { path = "../service" }
|
||||
tracing = "0.1.32"
|
||||
tracing-subscriber = { version = "0.3.9", features = ["env-filter"] }
|
||||
dirs = "4.0.0"
|
||||
|
||||
[dependencies.tokio]
|
||||
version = "1.17.0"
|
||||
features = ["rt"]
|
||||
features = ["rt"]
|
||||
|
|
|
|||
|
|
@ -3,18 +3,15 @@
|
|||
|
||||
use pop_launcher_plugins as plugins;
|
||||
use pop_launcher_service as service;
|
||||
use std::io;
|
||||
|
||||
#[tokio::main(flavor = "current_thread")]
|
||||
async fn main() {
|
||||
tracing_subscriber::fmt()
|
||||
.with_writer(io::stderr)
|
||||
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
|
||||
.init();
|
||||
|
||||
if let Some(plugin) = std::env::args().next() {
|
||||
let start = plugin.rfind('/').map(|v| v + 1).unwrap_or(0);
|
||||
let cmd = &plugin.as_str()[start..];
|
||||
|
||||
init_logging(cmd);
|
||||
|
||||
match cmd {
|
||||
"calc" => plugins::calc::main().await,
|
||||
"desktop-entries" => plugins::desktop_entries::main().await,
|
||||
|
|
@ -33,3 +30,28 @@ async fn main() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn init_logging(cmd: &str) {
|
||||
let logdir = match dirs::state_dir() {
|
||||
Some(dir) => dir.join("pop-launcher/"),
|
||||
None => dirs::home_dir()
|
||||
.expect("home directory required")
|
||||
.join(".cache/pop-launcher"),
|
||||
};
|
||||
|
||||
let _ = std::fs::create_dir_all(&logdir);
|
||||
|
||||
let logfile = std::fs::OpenOptions::new()
|
||||
.create(true)
|
||||
.truncate(true)
|
||||
.write(true)
|
||||
.open(logdir.join([cmd, ".log"].concat().as_str()).as_path());
|
||||
|
||||
if let Ok(file) = logfile {
|
||||
use tracing_subscriber::{fmt, EnvFilter};
|
||||
fmt()
|
||||
.with_env_filter(EnvFilter::from_default_env())
|
||||
.with_writer(file)
|
||||
.init();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue