chore: cleanup logs

This commit is contained in:
Ashley Wulber 2025-09-12 17:39:37 -04:00 committed by Michael Murphy
parent da11207f12
commit 79bf2cb4f8
16 changed files with 396 additions and 169 deletions

186
Cargo.lock generated
View file

@ -938,6 +938,33 @@ dependencies = [
"unicode-width", "unicode-width",
] ]
[[package]]
name = "color-eyre"
version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e5920befb47832a6d61ee3a3a846565cfa39b331331e68a3b1d1116630f2f26d"
dependencies = [
"backtrace",
"color-spantrace",
"eyre",
"indenter",
"once_cell",
"owo-colors",
"tracing-error",
]
[[package]]
name = "color-spantrace"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b8b88ea9df13354b55bc7234ebcce36e6ef896aca2e42a15de9e10edce01b427"
dependencies = [
"once_cell",
"owo-colors",
"tracing-core",
"tracing-error",
]
[[package]] [[package]]
name = "color_quant" name = "color_quant"
version = "1.1.0" version = "1.1.0"
@ -1176,6 +1203,7 @@ dependencies = [
"chrono", "chrono",
"chrono-tz", "chrono-tz",
"clap_lex", "clap_lex",
"color-eyre",
"cosmic-applets-config", "cosmic-applets-config",
"cosmic-bg-config", "cosmic-bg-config",
"cosmic-client-toolkit", "cosmic-client-toolkit",
@ -1189,7 +1217,6 @@ dependencies = [
"cosmic-settings-daemon-config", "cosmic-settings-daemon-config",
"cosmic-settings-subscriptions", "cosmic-settings-subscriptions",
"dirs 6.0.0", "dirs 6.0.0",
"env_logger",
"freedesktop_entry_parser", "freedesktop_entry_parser",
"futures-util", "futures-util",
"greetd_ipc", "greetd_ipc",
@ -1198,7 +1225,6 @@ dependencies = [
"icu", "icu",
"kdl", "kdl",
"libcosmic", "libcosmic",
"log",
"logind-zbus", "logind-zbus",
"nix 0.29.0", "nix 0.29.0",
"pam-client", "pam-client",
@ -1208,6 +1234,9 @@ dependencies = [
"shlex", "shlex",
"timedate-zbus", "timedate-zbus",
"tokio", "tokio",
"tracing",
"tracing-journald",
"tracing-subscriber",
"upower_dbus", "upower_dbus",
"vergen", "vergen",
"wayland-client", "wayland-client",
@ -1221,29 +1250,31 @@ name = "cosmic-greeter-config"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"cosmic-config", "cosmic-config",
"log",
"serde", "serde",
"tracing",
] ]
[[package]] [[package]]
name = "cosmic-greeter-daemon" name = "cosmic-greeter-daemon"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"color-eyre",
"cosmic-applets-config", "cosmic-applets-config",
"cosmic-bg-config", "cosmic-bg-config",
"cosmic-comp-config", "cosmic-comp-config",
"cosmic-config", "cosmic-config",
"cosmic-randr-shell", "cosmic-randr-shell",
"cosmic-theme", "cosmic-theme",
"env_logger",
"kdl", "kdl",
"libc", "libc",
"log",
"nix 0.29.0", "nix 0.29.0",
"pwd", "pwd",
"ron 0.10.1", "ron 0.10.1",
"serde", "serde",
"tokio", "tokio",
"tracing",
"tracing-journald",
"tracing-subscriber",
"xdg 3.0.0", "xdg 3.0.0",
"zbus 5.10.0", "zbus 5.10.0",
] ]
@ -1796,19 +1827,6 @@ dependencies = [
"syn 2.0.106", "syn 2.0.106",
] ]
[[package]]
name = "env_logger"
version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4cd405aab171cb85d6735e5c8d9db038c17d3ca007a4d2c25f337935c3d90580"
dependencies = [
"humantime",
"is-terminal",
"log",
"regex",
"termcolor",
]
[[package]] [[package]]
name = "equivalent" name = "equivalent"
version = "1.0.2" version = "1.0.2"
@ -1888,6 +1906,16 @@ dependencies = [
"pin-project-lite", "pin-project-lite",
] ]
[[package]]
name = "eyre"
version = "0.6.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7cd915d99f24784cdc19fd37ef22b97e3ff0ae756c7e492e9fbfe897d61e2aec"
dependencies = [
"indenter",
"once_cell",
]
[[package]] [[package]]
name = "fast-srgb8" name = "fast-srgb8"
version = "1.0.0" version = "1.0.0"
@ -2529,12 +2557,6 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dfa686283ad6dd069f105e5ab091b04c62850d3e4cf5d67debad1933f55023df" checksum = "dfa686283ad6dd069f105e5ab091b04c62850d3e4cf5d67debad1933f55023df"
[[package]]
name = "humantime"
version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b112acc8b3adf4b107a8ec20977da0273a8c386765a3ec0229bd500a1443f9f"
[[package]] [[package]]
name = "i18n-config" name = "i18n-config"
version = "0.4.8" version = "0.4.8"
@ -3390,6 +3412,12 @@ dependencies = [
"arrayvec", "arrayvec",
] ]
[[package]]
name = "indenter"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "964de6e86d545b246d84badc0fef527924ace5134f30641c203ef52ba83f58d5"
[[package]] [[package]]
name = "indexmap" name = "indexmap"
version = "1.9.3" version = "1.9.3"
@ -3510,17 +3538,6 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "is-terminal"
version = "0.4.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e04d7f318608d35d4b61ddd75cbdaee86b023ebe2bd5a66ee0915f0bf93095a9"
dependencies = [
"hermit-abi 0.5.2",
"libc",
"windows-sys 0.59.0",
]
[[package]] [[package]]
name = "itertools" name = "itertools"
version = "0.12.1" version = "0.12.1"
@ -3932,6 +3949,15 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "matchers"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d1525a2a28c7f4fa0fc98bb91ae755d1e2d1505079e05539e35bc876b5d65ae9"
dependencies = [
"regex-automata 0.4.10",
]
[[package]] [[package]]
name = "memchr" name = "memchr"
version = "2.7.5" version = "2.7.5"
@ -4190,6 +4216,15 @@ version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5e0826a989adedc2a244799e823aece04662b66609d96af8dff7ac6df9a8925d" checksum = "5e0826a989adedc2a244799e823aece04662b66609d96af8dff7ac6df9a8925d"
[[package]]
name = "nu-ansi-term"
version = "0.50.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d4a28e057d01f97e61255210fcff094d74ed0466038633e95017f5beb68e4399"
dependencies = [
"windows-sys 0.52.0",
]
[[package]] [[package]]
name = "num" name = "num"
version = "0.4.3" version = "0.4.3"
@ -4670,6 +4705,12 @@ dependencies = [
"ttf-parser 0.25.1", "ttf-parser 0.25.1",
] ]
[[package]]
name = "owo-colors"
version = "4.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "48dd4f4a2c8405440fd0462561f0e5806bd0f77e86f51c761481bdd4018b545e"
[[package]] [[package]]
name = "palette" name = "palette"
version = "0.7.6" version = "0.7.6"
@ -5721,6 +5762,15 @@ dependencies = [
"digest", "digest",
] ]
[[package]]
name = "sharded-slab"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6"
dependencies = [
"lazy_static",
]
[[package]] [[package]]
name = "shlex" name = "shlex"
version = "1.3.0" version = "1.3.0"
@ -6076,6 +6126,15 @@ dependencies = [
"syn 2.0.106", "syn 2.0.106",
] ]
[[package]]
name = "thread_local"
version = "1.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f60246a4944f24f6e018aa17cdeffb7818b76356965d03b07d6a9886e8962185"
dependencies = [
"cfg-if",
]
[[package]] [[package]]
name = "time" name = "time"
version = "0.3.41" version = "0.3.41"
@ -6301,6 +6360,57 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9d12581f227e93f094d3af2ae690a574abb8a2b9b7a96e7cfe9647b2b617678" checksum = "b9d12581f227e93f094d3af2ae690a574abb8a2b9b7a96e7cfe9647b2b617678"
dependencies = [ dependencies = [
"once_cell", "once_cell",
"valuable",
]
[[package]]
name = "tracing-error"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b1581020d7a273442f5b45074a6a57d5757ad0a47dac0e9f0bd57b81936f3db"
dependencies = [
"tracing",
"tracing-subscriber",
]
[[package]]
name = "tracing-journald"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc0b4143302cf1022dac868d521e36e8b27691f72c84b3311750d5188ebba657"
dependencies = [
"libc",
"tracing-core",
"tracing-subscriber",
]
[[package]]
name = "tracing-log"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3"
dependencies = [
"log",
"once_cell",
"tracing-core",
]
[[package]]
name = "tracing-subscriber"
version = "0.3.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2054a14f5307d601f88daf0553e1cbf472acc4f2c51afab632431cdcd72124d5"
dependencies = [
"matchers",
"nu-ansi-term",
"once_cell",
"regex-automata 0.4.10",
"sharded-slab",
"smallvec",
"thread_local",
"tracing",
"tracing-core",
"tracing-log",
] ]
[[package]] [[package]]
@ -6514,6 +6624,12 @@ version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be"
[[package]]
name = "valuable"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65"
[[package]] [[package]]
name = "vergen" name = "vergen"
version = "8.3.2" version = "8.3.2"

View file

@ -23,7 +23,6 @@ cosmic-config = { workspace = true, features = ["calloop", "macro"] }
cosmic-greeter-config.workspace = true cosmic-greeter-config.workspace = true
cosmic-greeter-daemon = { path = "daemon" } cosmic-greeter-daemon = { path = "daemon" }
dirs = "6" dirs = "6"
env_logger.workspace = true
freedesktop_entry_parser = "1.3.0" freedesktop_entry_parser = "1.3.0"
libcosmic = { workspace = true, features = [ libcosmic = { workspace = true, features = [
"autosize", "autosize",
@ -34,7 +33,9 @@ libcosmic = { workspace = true, features = [
"tokio", "tokio",
"dbus-config", "dbus-config",
] } ] }
log.workspace = true tracing.workspace = true
tracing-journald = { workspace = true, optional = true }
tracing-subscriber = { workspace = true, features = ["env-filter"] }
pam-client = "0.5.0" pam-client = "0.5.0"
pwd.workspace = true pwd.workspace = true
ron.workspace = true ron.workspace = true
@ -79,15 +80,16 @@ futures-util = "0.3.30"
timedate-zbus = { git = "https://github.com/pop-os/dbus-settings-bindings" } timedate-zbus = { git = "https://github.com/pop-os/dbus-settings-bindings" }
cosmic-randr-shell = { workspace = true } cosmic-randr-shell = { workspace = true }
kdl.workspace = true kdl.workspace = true
color-eyre.workspace = true
[dependencies.greetd_ipc] [dependencies.greetd_ipc]
version = "0.10.3" version = "0.10.3"
features = ["tokio-codec"] features = ["tokio-codec"]
[features] [features]
default = ["logind", "networkmanager", "upower"] default = ["logind", "networkmanager", "upower", "systemd"]
logind = ["logind-zbus", "zbus"] logind = ["logind-zbus", "zbus", "systemd"]
systemd = ["tracing-journald"]
networkmanager = ["cosmic-dbus-networkmanager", "zbus"] networkmanager = ["cosmic-dbus-networkmanager", "zbus"]
upower = ["upower_dbus", "zbus"] upower = ["upower_dbus", "zbus"]
zbus = ["dep:zbus", "nix"] zbus = ["dep:zbus", "nix"]
@ -110,8 +112,10 @@ resolver = "2"
rust-version = "1.85.0" rust-version = "1.85.0"
[workspace.dependencies] [workspace.dependencies]
env_logger = "0.10.2" tracing = "0.1"
log = "0.4.22" tracing-journald = { version = "0.3" }
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
color-eyre = "0.6.5"
# Fix zbus compilation by manually adding nix with user feature # Fix zbus compilation by manually adding nix with user feature
nix = { version = "0.29", features = ["user"] } nix = { version = "0.29", features = ["user"] }

View file

@ -8,5 +8,5 @@ license = "GPL-3.0-only"
[dependencies] [dependencies]
cosmic-config.workspace = true cosmic-config.workspace = true
log.workspace = true tracing.workspace = true
serde.workspace = true serde.workspace = true

View file

@ -35,14 +35,14 @@ where
let config = C::get_entry(&handler) let config = C::get_entry(&handler)
.inspect_err(|(errors, _)| { .inspect_err(|(errors, _)| {
for err in errors.iter().filter(|err| err.is_err()) { for err in errors.iter().filter(|err| err.is_err()) {
log::error!("{err}") tracing::error!("{err}")
} }
}) })
.unwrap_or_else(|(_, config)| config); .unwrap_or_else(|(_, config)| config);
(config, Some(handler)) (config, Some(handler))
} }
Err(e) => { Err(e) => {
log::error!("Failed to get settings for `{APP_ID}` (v {CONFIG_VERSION}): {e:?}"); tracing::error!("Failed to get settings for `{APP_ID}` (v {CONFIG_VERSION}): {e:?}");
(C::default(), None) (C::default(), None)
} }
} }

View file

@ -1,3 +1,3 @@
#!/bin/sh #!/bin/sh
rm -rf /run/cosmic-greeter/cosmic/com.system76.CosmicSettingsDaemon/v1/* rm -rf /run/cosmic-greeter/cosmic/com.system76.CosmicSettingsDaemon/v1/* > /dev/null 2>&1
exec cosmic-comp systemd-cat -t cosmic-greeter cosmic-greeter exec cosmic-comp cosmic-greeter > /dev/null 2>&1

View file

@ -6,14 +6,16 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
tracing-subscriber = { workspace = true, features = ["env-filter"] }
libc = "0.2"
cosmic-applets-config.workspace = true cosmic-applets-config.workspace = true
cosmic-bg-config.workspace = true cosmic-bg-config.workspace = true
cosmic-comp-config.workspace = true cosmic-comp-config.workspace = true
cosmic-config.workspace = true cosmic-config.workspace = true
cosmic-theme.workspace = true cosmic-theme.workspace = true
env_logger.workspace = true tracing.workspace = true
libc = "0.2" tracing-journald = { workspace = true, optional = true }
log.workspace = true color-eyre.workspace = true
nix.workspace = true nix.workspace = true
pwd.workspace = true pwd.workspace = true
ron.workspace = true ron.workspace = true
@ -25,3 +27,7 @@ kdl.workspace = true
#TODO: reduce features #TODO: reduce features
tokio = { workspace = true, features = ["full"] } tokio = { workspace = true, features = ["full"] }
xdg = "3.0.0" xdg = "3.0.0"
[features]
default = ["systemd"]
systemd = ["tracing-journald"]

View file

@ -50,7 +50,7 @@ impl UserData {
self.bg_path_data.insert(path.clone(), bytes); self.bg_path_data.insert(path.clone(), bytes);
} }
Err(err) => { Err(err) => {
log::error!("failed to read wallpaper {:?}: {:?}", path, err); tracing::error!("failed to read wallpaper {:?}: {:?}", path, err);
} }
} }
} }
@ -80,7 +80,7 @@ impl UserData {
self.icon_opt = Some(icon_data); self.icon_opt = Some(icon_data);
} }
Err(err) => { Err(err) => {
log::error!("failed to read icon {:?}: {:?}", icon_path, err); tracing::error!("failed to read icon {:?}: {:?}", icon_path, err);
} }
} }
} }
@ -92,12 +92,12 @@ impl UserData {
is_dark = theme_mode.is_dark; is_dark = theme_mode.is_dark;
} }
Err((errs, theme_mode)) => { Err((errs, theme_mode)) => {
log::error!("failed to load cosmic-theme config: {:?}", errs); tracing::error!("failed to load cosmic-theme config: {:?}", errs);
is_dark = theme_mode.is_dark; is_dark = theme_mode.is_dark;
} }
}, },
Err(err) => { Err(err) => {
log::error!("failed to create cosmic-theme mode helper: {:?}", err); tracing::error!("failed to create cosmic-theme mode helper: {:?}", err);
} }
} }
@ -111,12 +111,12 @@ impl UserData {
self.theme_opt = Some(theme); self.theme_opt = Some(theme);
} }
Err((errs, theme)) => { Err((errs, theme)) => {
log::error!("failed to load cosmic-theme config: {:?}", errs); tracing::error!("failed to load cosmic-theme config: {:?}", errs);
self.theme_opt = Some(theme); self.theme_opt = Some(theme);
} }
}, },
Err(err) => { Err(err) => {
log::error!("failed to create cosmic-theme config helper: {:?}", err); tracing::error!("failed to create cosmic-theme config helper: {:?}", err);
} }
} }
@ -130,12 +130,12 @@ impl UserData {
self.theme_builder_opt = Some(theme); self.theme_builder_opt = Some(theme);
} }
Err((errs, theme)) => { Err((errs, theme)) => {
log::error!("failed to load cosmic-theme builder config: {:?}", errs); tracing::error!("failed to load cosmic-theme builder config: {:?}", errs);
self.theme_builder_opt = Some(theme); self.theme_builder_opt = Some(theme);
} }
}, },
Err(err) => { Err(err) => {
log::error!( tracing::error!(
"failed to create cosmic-theme builder config helper: {:?}", "failed to create cosmic-theme builder config helper: {:?}",
err err
); );
@ -149,12 +149,12 @@ impl UserData {
self.bg_state = state; self.bg_state = state;
} }
Err((errs, state)) => { Err((errs, state)) => {
log::error!("failed to load cosmic-bg state: {:?}", errs); tracing::error!("failed to load cosmic-bg state: {:?}", errs);
self.bg_state = state; self.bg_state = state;
} }
}, },
Err(err) => { Err(err) => {
log::error!("failed to create cosmic-bg state helper: {:?}", err); tracing::error!("failed to create cosmic-bg state helper: {:?}", err);
} }
} }
self.load_wallpapers_as_user(); self.load_wallpapers_as_user();
@ -167,14 +167,14 @@ impl UserData {
self.accessibility_zoom = config.accessibility_zoom; self.accessibility_zoom = config.accessibility_zoom;
} }
Err((errs, config)) => { Err((errs, config)) => {
log::error!("errors loading cosmic-comp config: {:?}", errs); tracing::error!("errors loading cosmic-comp config: {:?}", errs);
self.xkb_config_opt = Some(config.xkb_config); self.xkb_config_opt = Some(config.xkb_config);
self.accessibility_zoom = config.accessibility_zoom; self.accessibility_zoom = config.accessibility_zoom;
} }
}; };
} }
Err(err) => { Err(err) => {
log::error!("failed to create cosmic-comp config handler: {}", err); tracing::error!("failed to create cosmic-comp config handler: {}", err);
} }
}; };
@ -198,12 +198,12 @@ impl UserData {
self.time_applet_config = config; self.time_applet_config = config;
} }
Err((errs, config)) => { Err((errs, config)) => {
log::error!("failed to load time applet config: {:?}", errs); tracing::error!("failed to load time applet config: {:?}", errs);
self.time_applet_config = config; self.time_applet_config = config;
} }
}, },
Err(err) => { Err(err) => {
log::error!( tracing::error!(
"failed to create CosmicAppletTime config handler: {:?}", "failed to create CosmicAppletTime config handler: {:?}",
err err
); );

View file

@ -1,5 +1,10 @@
use color_eyre::eyre::Context;
use color_eyre::eyre::WrapErr;
use cosmic_greeter_daemon::UserData; use cosmic_greeter_daemon::UserData;
use std::{env, error::Error, future::pending, io, path::Path}; use std::{env, error::Error, future::pending, io, path::Path};
use tracing::metadata::LevelFilter;
use tracing::{error, warn};
use tracing_subscriber::{fmt, prelude::*, EnvFilter};
use zbus::{connection::Builder, DBusError}; use zbus::{connection::Builder, DBusError};
//IMPORTANT: this function is critical to the security of this proxy. It must ensure that the //IMPORTANT: this function is critical to the security of this proxy. It must ensure that the
@ -99,7 +104,35 @@ impl GreeterProxy {
#[tokio::main] #[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> { async fn main() -> Result<(), Box<dyn Error>> {
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("warn")).init(); color_eyre::install().wrap_err("failed to install color_eyre error handler")?;
let trace = tracing_subscriber::registry();
let env_filter = EnvFilter::builder()
.with_default_directive(LevelFilter::WARN.into())
.from_env_lossy();
#[cfg(feature = "systemd")]
if let Ok(journald) = tracing_journald::layer() {
trace
.with(journald)
.with(env_filter)
.try_init()
.wrap_err("failed to initialize logger")?;
} else {
trace
.with(fmt::layer())
.with(env_filter)
.try_init()
.wrap_err("failed to initialize logger")?;
warn!("failed to connect to journald")
}
#[cfg(not(feature = "systemd"))]
trace
.with(fmt::layer())
.with(env_filter)
.try_init()
.wrap_err("failed to initialize logger")?;
let _conn = Builder::system()? let _conn = Builder::system()?
.name("com.system76.CosmicGreeter")? .name("com.system76.CosmicGreeter")?

View file

@ -80,7 +80,7 @@ impl<M: From<Message> + Send + 'static> Common<M> {
) { ) {
Ok(config_handler) => Some(config_handler), Ok(config_handler) => Some(config_handler),
Err(err) => { Err(err) => {
log::error!("failed to create cosmic-comp config handler: {}", err); tracing::error!("failed to create cosmic-comp config handler: {}", err);
None None
} }
}; };
@ -88,7 +88,7 @@ impl<M: From<Message> + Send + 'static> Common<M> {
let layouts_opt = match xkb_data::all_keyboard_layouts() { let layouts_opt = match xkb_data::all_keyboard_layouts() {
Ok(ok) => Some(Arc::new(ok)), Ok(ok) => Some(Arc::new(ok)),
Err(err) => { Err(err) => {
log::warn!("failed to load keyboard layouts: {}", err); tracing::warn!("failed to load keyboard layouts: {}", err);
None None
} }
}; };
@ -141,8 +141,8 @@ impl<M: From<Message> + Send + 'static> Common<M> {
} }
if let Some(comp_config_handler) = &self.comp_config_handler { if let Some(comp_config_handler) = &self.comp_config_handler {
match comp_config_handler.set("xkb_config", xkb_config) { match comp_config_handler.set("xkb_config", xkb_config) {
Ok(()) => log::info!("updated cosmic-comp xkb_config"), Ok(()) => tracing::info!("updated cosmic-comp xkb_config"),
Err(err) => log::error!("failed to update cosmic-comp xkb_config: {}", err), Err(err) => tracing::error!("failed to update cosmic-comp xkb_config: {}", err),
} }
} }
} }
@ -158,7 +158,7 @@ impl<M: From<Message> + Send + 'static> Common<M> {
continue; continue;
}; };
log::info!("updating wallpaper for {:?}", output_name); tracing::info!("updating wallpaper for {:?}", output_name);
for (wallpaper_output_name, wallpaper_source) in user_data.bg_state.wallpapers.iter() { for (wallpaper_output_name, wallpaper_source) in user_data.bg_state.wallpapers.iter() {
if wallpaper_output_name == output_name { if wallpaper_output_name == output_name {
@ -171,7 +171,7 @@ impl<M: From<Message> + Send + 'static> Common<M> {
//TODO: what to do about duplicates? //TODO: what to do about duplicates?
} }
None => { None => {
log::warn!( tracing::warn!(
"output {}: failed to find wallpaper data for source {:?}", "output {}: failed to find wallpaper data for source {:?}",
output_name, output_name,
path path
@ -182,7 +182,11 @@ impl<M: From<Message> + Send + 'static> Common<M> {
} }
BgSource::Color(color) => { BgSource::Color(color) => {
//TODO: support color sources //TODO: support color sources
log::warn!("output {}: unsupported source {:?}", output_name, color); tracing::warn!(
"output {}: unsupported source {:?}",
output_name,
color
);
} }
} }
} }
@ -234,7 +238,7 @@ impl<M: From<Message> + Send + 'static> Common<M> {
} }
} }
} }
log::info!("{:?}", self.active_layouts); tracing::info!("{:?}", self.active_layouts);
} }
} }
} }
@ -299,7 +303,7 @@ impl<M: From<Message> + Send + 'static> Common<M> {
.get(&surface_id) .get(&surface_id)
.and_then(|id| self.text_input_ids.get(id)) .and_then(|id| self.text_input_ids.get(id))
{ {
log::info!("focus surface found id {:?}", text_input_id); tracing::info!("focus surface found id {:?}", text_input_id);
return widget::text_input::focus(text_input_id.clone()); return widget::text_input::focus(text_input_id.clone());
} }
} }

View file

@ -5,6 +5,7 @@ mod ipc;
use crate::wayland::{self, WaylandUpdate}; use crate::wayland::{self, WaylandUpdate};
use cctk::sctk::reexports::calloop; use cctk::sctk::reexports::calloop;
use color_eyre::eyre::WrapErr;
use cosmic::app::{Core, Settings, Task}; use cosmic::app::{Core, Settings, Task};
use cosmic::cctk::wayland_protocols::xdg::shell::client::xdg_positioner::Gravity; use cosmic::cctk::wayland_protocols::xdg::shell::client::xdg_positioner::Gravity;
use cosmic::iced::event::listen_with; use cosmic::iced::event::listen_with;
@ -56,6 +57,9 @@ use std::{
}; };
use tokio::process::Child; use tokio::process::Child;
use tokio::time; use tokio::time;
use tracing::metadata::LevelFilter;
use tracing::warn;
use tracing_subscriber::{EnvFilter, fmt, prelude::*};
use wayland_client::{Proxy, protocol::wl_output::WlOutput}; use wayland_client::{Proxy, protocol::wl_output::WlOutput};
use zbus::{Connection, proxy}; use zbus::{Connection, proxy};
@ -111,7 +115,35 @@ fn user_data_fallback() -> Vec<UserData> {
} }
pub fn main() -> Result<(), Box<dyn Error>> { pub fn main() -> Result<(), Box<dyn Error>> {
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("warn")).init(); color_eyre::install().wrap_err("failed to install color_eyre error handler")?;
let trace = tracing_subscriber::registry();
let env_filter = EnvFilter::builder()
.with_default_directive(LevelFilter::WARN.into())
.from_env_lossy();
#[cfg(feature = "systemd")]
if let Ok(journald) = tracing_journald::layer() {
trace
.with(journald)
.with(env_filter)
.try_init()
.wrap_err("failed to initialize logger")?;
} else {
trace
.with(fmt::layer())
.with(env_filter)
.try_init()
.wrap_err("failed to initialize logger")?;
warn!("failed to connect to journald")
}
#[cfg(not(feature = "systemd"))]
trace
.with(fmt::layer())
.with(env_filter)
.try_init()
.wrap_err("failed to initialize logger")?;
crate::localize::localize(); crate::localize::localize();
let runtime = tokio::runtime::Builder::new_current_thread() let runtime = tokio::runtime::Builder::new_current_thread()
@ -121,7 +153,7 @@ pub fn main() -> Result<(), Box<dyn Error>> {
let mut user_datas = match runtime.block_on(user_data_dbus()) { let mut user_datas = match runtime.block_on(user_data_dbus()) {
Ok(ok) => ok, Ok(ok) => ok,
Err(err) => { Err(err) => {
log::error!("failed to load user data from daemon: {}", err); tracing::error!("failed to load user data from daemon: {}", err);
user_data_fallback() user_data_fallback()
} }
}; };
@ -163,7 +195,7 @@ pub fn main() -> Result<(), Box<dyn Error>> {
let read_dir = match fs::read_dir(&session_dir) { let read_dir = match fs::read_dir(&session_dir) {
Ok(ok) => ok, Ok(ok) => ok,
Err(err) => { Err(err) => {
log::warn!( tracing::warn!(
"failed to read session directory {:?}: {:?}", "failed to read session directory {:?}: {:?}",
session_dir, session_dir,
err err
@ -176,7 +208,7 @@ pub fn main() -> Result<(), Box<dyn Error>> {
let dir_entry = match dir_entry_res { let dir_entry = match dir_entry_res {
Ok(ok) => ok, Ok(ok) => ok,
Err(err) => { Err(err) => {
log::warn!( tracing::warn!(
"failed to read session directory {:?} entry: {:?}", "failed to read session directory {:?} entry: {:?}",
session_dir, session_dir,
err err
@ -188,7 +220,7 @@ pub fn main() -> Result<(), Box<dyn Error>> {
let entry = match freedesktop_entry_parser::parse_entry(dir_entry.path()) { let entry = match freedesktop_entry_parser::parse_entry(dir_entry.path()) {
Ok(ok) => ok, Ok(ok) => ok,
Err(err) => { Err(err) => {
log::warn!( tracing::warn!(
"failed to read session file {:?}: {:?}", "failed to read session file {:?}: {:?}",
dir_entry.path(), dir_entry.path(),
err err
@ -200,7 +232,7 @@ pub fn main() -> Result<(), Box<dyn Error>> {
let name = match entry.section("Desktop Entry").attr("Name") { let name = match entry.section("Desktop Entry").attr("Name") {
Some(some) => some, Some(some) => some,
None => { None => {
log::warn!( tracing::warn!(
"failed to read session file {:?}: no Desktop Entry/Name attribute", "failed to read session file {:?}: no Desktop Entry/Name attribute",
dir_entry.path() dir_entry.path()
); );
@ -211,7 +243,7 @@ pub fn main() -> Result<(), Box<dyn Error>> {
let exec = match entry.section("Desktop Entry").attr("Exec") { let exec = match entry.section("Desktop Entry").attr("Exec") {
Some(some) => some, Some(some) => some,
None => { None => {
log::warn!( tracing::warn!(
"failed to read session file {:?}: no Desktop Entry/Exec attribute", "failed to read session file {:?}: no Desktop Entry/Exec attribute",
dir_entry.path() dir_entry.path()
); );
@ -254,7 +286,7 @@ pub fn main() -> Result<(), Box<dyn Error>> {
} }
} }
None => { None => {
log::warn!( tracing::warn!(
"failed to parse session file {:?} Exec field {:?}", "failed to parse session file {:?} Exec field {:?}",
dir_entry.path(), dir_entry.path(),
exec exec
@ -263,10 +295,10 @@ pub fn main() -> Result<(), Box<dyn Error>> {
} }
}; };
log::info!("session {} using command {:?} env {:?}", name, command, env); tracing::info!("session {} using command {:?} env {:?}", name, command, env);
match sessions.insert(name.to_string(), (command, env)) { match sessions.insert(name.to_string(), (command, env)) {
Some(some) => { Some(some) => {
log::warn!("session {} overwrote old command {:?}", name, some); tracing::warn!("session {} overwrote old command {:?}", name, some);
} }
None => {} None => {}
} }
@ -454,16 +486,16 @@ impl App {
if let Some(mut stdin) = p.stdin.take() { if let Some(mut stdin) = p.stdin.take() {
if let Err(err) = stdin.write_all(kdl_doc.as_bytes()).await { if let Err(err) = stdin.write_all(kdl_doc.as_bytes()).await {
log::error!("Failed to write KDL to stdin: {err:?}"); tracing::error!("Failed to write KDL to stdin: {err:?}");
} }
if let Err(err) = stdin.flush().await { if let Err(err) = stdin.flush().await {
log::error!("Failed to flush stdin: {err:?}"); tracing::error!("Failed to flush stdin: {err:?}");
} }
} }
log::debug!("executing {task:?}"); tracing::debug!("executing {task:?}");
let status = p.wait().await; let status = p.wait().await;
if let Err(err) = status { if let Err(err) = status {
log::error!("Randr error: {err:?}"); tracing::error!("Randr error: {err:?}");
} }
}) })
.discard() .discard()
@ -1097,7 +1129,7 @@ impl cosmic::Application for App {
Message::OutputEvent(output_event, output) => { Message::OutputEvent(output_event, output) => {
match output_event { match output_event {
OutputEvent::Created(output_info_opt) => { OutputEvent::Created(output_info_opt) => {
log::info!("output {}: created", output.id()); tracing::info!("output {}: created", output.id());
let surface_id = SurfaceId::unique(); let surface_id = SurfaceId::unique();
let subsurface_id = SurfaceId::unique(); let subsurface_id = SurfaceId::unique();
@ -1107,7 +1139,7 @@ impl cosmic::Application for App {
match self.common.surface_ids.insert(output.clone(), surface_id) { match self.common.surface_ids.insert(output.clone(), surface_id) {
Some(old_surface_id) => { Some(old_surface_id) => {
//TODO: remove old surface? //TODO: remove old surface?
log::warn!( tracing::warn!(
"output {}: already had surface ID {:?}", "output {}: already had surface ID {:?}",
output.id(), output.id(),
old_surface_id old_surface_id
@ -1139,11 +1171,11 @@ impl cosmic::Application for App {
.insert(output_name.clone(), text_input_id.clone()); .insert(output_name.clone(), text_input_id.clone());
} }
None => { None => {
log::warn!("output {}: no output name", output.id()); tracing::warn!("output {}: no output name", output.id());
} }
}, },
None => { None => {
log::warn!("output {}: no output info", output.id()); tracing::warn!("output {}: no output info", output.id());
} }
} }
@ -1208,7 +1240,7 @@ impl cosmic::Application for App {
]); ]);
} }
OutputEvent::Removed => { OutputEvent::Removed => {
log::info!("output {}: removed", output.id()); tracing::info!("output {}: removed", output.id());
match self.common.surface_ids.remove(&output) { match self.common.surface_ids.remove(&output) {
Some(surface_id) => { Some(surface_id) => {
self.common.surface_images.remove(&surface_id); self.common.surface_images.remove(&surface_id);
@ -1219,12 +1251,12 @@ impl cosmic::Application for App {
return destroy_layer_surface(surface_id); return destroy_layer_surface(surface_id);
} }
None => { None => {
log::warn!("output {}: no surface found", output.id()); tracing::warn!("output {}: no surface found", output.id());
} }
} }
} }
OutputEvent::InfoUpdate(_output_info) => { OutputEvent::InfoUpdate(_output_info) => {
log::info!("output {}: info update", output.id()); tracing::info!("output {}: info update", output.id());
} }
} }
} }
@ -1319,7 +1351,7 @@ impl cosmic::Application for App {
.map(|uid| self.flags.greeter_config.users.entry(uid)) .map(|uid| self.flags.greeter_config.users.entry(uid))
}) })
}) else { }) else {
log::error!( tracing::error!(
"Couldn't find user: {:?} {:?}", "Couldn't find user: {:?} {:?}",
self.selected_username.username, self.selected_username.username,
self.selected_username.data_idx, self.selected_username.data_idx,
@ -1328,7 +1360,7 @@ impl cosmic::Application for App {
}; };
let Some(handler) = self.flags.greeter_config_handler.as_mut() else { let Some(handler) = self.flags.greeter_config_handler.as_mut() else {
log::error!( tracing::error!(
"Failed to update config for {} (UID: {}): no config handler", "Failed to update config for {} (UID: {}): no config handler",
self.selected_username.username, self.selected_username.username,
user_entry.key() user_entry.key()
@ -1339,7 +1371,7 @@ impl cosmic::Application for App {
let uid = *user_entry.key(); let uid = *user_entry.key();
self.flags.greeter_config.last_user = Some(uid); self.flags.greeter_config.last_user = Some(uid);
if let Err(err) = handler.set("last_user", &self.flags.greeter_config.last_user) { if let Err(err) = handler.set("last_user", &self.flags.greeter_config.last_user) {
log::error!( tracing::error!(
"Failed to set {:?} as last user: {:?}", "Failed to set {:?} as last user: {:?}",
self.flags.greeter_config.last_user, self.flags.greeter_config.last_user,
err err
@ -1376,7 +1408,7 @@ impl cosmic::Application for App {
// .greeter_config // .greeter_config
// .set_users(&handler, self.flags.greeter_config.users.clone()) // .set_users(&handler, self.flags.greeter_config.users.clone())
if let Err(err) = handler.set("users", &self.flags.greeter_config.users) { if let Err(err) = handler.set("users", &self.flags.greeter_config.users) {
log::error!( tracing::error!(
"Failed to set {} as last selected session for {} (UID: {}): {:?}", "Failed to set {} as last selected session for {} (UID: {}): {:?}",
self.selected_session, self.selected_session,
self.selected_username.username, self.selected_username.username,
@ -1421,7 +1453,7 @@ impl cosmic::Application for App {
match crate::logind::reboot().await { match crate::logind::reboot().await {
Ok(()) => (), Ok(()) => (),
Err(err) => { Err(err) => {
log::error!("failed to reboot: {:?}", err); tracing::error!("failed to reboot: {:?}", err);
} }
} }
}) })
@ -1433,7 +1465,7 @@ impl cosmic::Application for App {
match crate::logind::power_off().await { match crate::logind::power_off().await {
Ok(()) => (), Ok(()) => (),
Err(err) => { Err(err) => {
log::error!("failed to power off: {:?}", err); tracing::error!("failed to power off: {:?}", err);
} }
} }
}) })
@ -1463,7 +1495,7 @@ impl cosmic::Application for App {
match crate::logind::suspend().await { match crate::logind::suspend().await {
Ok(()) => (), Ok(()) => (),
Err(err) => { Err(err) => {
log::error!("failed to suspend: {:?}", err); tracing::error!("failed to suspend: {:?}", err);
} }
} }
}) })
@ -1543,7 +1575,7 @@ impl cosmic::Application for App {
if let Some(mut c) = self.accessibility.screen_reader.take() { if let Some(mut c) = self.accessibility.screen_reader.take() {
return cosmic::task::future::<(), ()>(async move { return cosmic::task::future::<(), ()>(async move {
if let Err(err) = c.kill().await { if let Err(err) = c.kill().await {
log::error!("Failed to stop screen reader: {err:?}"); tracing::error!("Failed to stop screen reader: {err:?}");
} }
}) })
.discard(); .discard();
@ -1590,7 +1622,7 @@ impl cosmic::Application for App {
_ = tx.send(Some(t)); _ = tx.send(Some(t));
} }
Err(err) => { Err(err) => {
log::error!("{err:?}"); tracing::error!("{err:?}");
_ = tx.send(None); _ = tx.send(None);
} }
}); });
@ -1672,7 +1704,7 @@ impl cosmic::Application for App {
.filter_map(|s| match KdlDocument::parse(s) { .filter_map(|s| match KdlDocument::parse(s) {
Ok(doc) => Some(doc), Ok(doc) => Some(doc),
Err(err) => { Err(err) => {
log::warn!("Invalid output KDL {err:?}"); tracing::warn!("Invalid output KDL {err:?}");
None None
} }
}) })
@ -1680,7 +1712,7 @@ impl cosmic::Application for App {
Ok(list) => list, Ok(list) => list,
Err(KdlParseWithError { list, errors }) => { Err(KdlParseWithError { list, errors }) => {
for err in errors { for err in errors {
log::warn!("KDL output error: {err:?}"); tracing::warn!("KDL output error: {err:?}");
} }
list list
} }
@ -1709,13 +1741,13 @@ impl cosmic::Application for App {
if let Some(list) = list { if let Some(list) = list {
tasks.push(self.exec_randr(list)) tasks.push(self.exec_randr(list))
} else { } else {
log::warn!("Failed to apply user display config"); tracing::warn!("Failed to apply user display config");
} }
return Task::batch(tasks); return Task::batch(tasks);
} }
Err(err) => { Err(err) => {
log::error!("Randr error: {err}"); tracing::error!("Randr error: {err}");
} }
}, },
Message::RepositionMenu(id, size) => { Message::RepositionMenu(id, size) => {
@ -1724,7 +1756,7 @@ impl cosmic::Application for App {
.iter() .iter()
.find_map(|(p, s)| (*p == id).then_some(s)) .find_map(|(p, s)| (*p == id).then_some(s))
else { else {
log::error!("Failed to find subsurface menu id"); tracing::error!("Failed to find subsurface menu id");
return Task::none(); return Task::none();
}; };
let loc = if size.width > 800. { let loc = if size.width > 800. {

View file

@ -31,7 +31,7 @@ pub fn subscription() -> Subscription<Message> {
let mut stream = match UnixStream::connect(&socket_path).await { let mut stream = match UnixStream::connect(&socket_path).await {
Ok(stream) => stream, Ok(stream) => stream,
Err(why) => { Err(why) => {
log::error!("greetd IPC socket connection failed: {why:?}"); tracing::error!("greetd IPC socket connection failed: {why:?}");
_ = sender.send(Message::Socket(SocketState::Error(Arc::new(why)))); _ = sender.send(Message::Socket(SocketState::Error(Arc::new(why))));
break; break;
@ -42,7 +42,7 @@ pub fn subscription() -> Subscription<Message> {
while let Some(request) = rx.recv().await { while let Some(request) = rx.recv().await {
if let Err(why) = request.write_to(&mut stream).await { if let Err(why) = request.write_to(&mut stream).await {
log::error!("error writing to GREETD_SOCK stream: {why:?}"); tracing::error!("error writing to GREETD_SOCK stream: {why:?}");
break; break;
} }
@ -96,7 +96,7 @@ pub fn subscription() -> Subscription<Message> {
match request { match request {
greetd_ipc::Request::CancelSession => { greetd_ipc::Request::CancelSession => {
// Do not send errors for cancel session to gui // Do not send errors for cancel session to gui
log::warn!( tracing::warn!(
"error while cancelling session: {}", "error while cancelling session: {}",
description description
); );
@ -123,7 +123,7 @@ pub fn subscription() -> Subscription<Message> {
_ = sender.send(Message::Exit).await; _ = sender.send(Message::Exit).await;
} }
greetd_ipc::Request::CancelSession => { greetd_ipc::Request::CancelSession => {
log::info!("greetd IPC session canceled"); tracing::info!("greetd IPC session canceled");
// Reconnect to socket // Reconnect to socket
break; break;
} }
@ -131,13 +131,13 @@ pub fn subscription() -> Subscription<Message> {
} }
} }
Err(err) => { Err(err) => {
log::error!("failed to read socket: {:?}", err); tracing::error!("failed to read socket: {:?}", err);
break; break;
} }
} }
} }
log::info!("reconnecting to greetd IPC socket"); tracing::info!("reconnecting to greetd IPC socket");
interval.tick().await; interval.tick().await;
} }

View file

@ -1,6 +1,7 @@
// Copyright 2023 System76 <info@system76.com> // Copyright 2023 System76 <info@system76.com>
// SPDX-License-Identifier: GPL-3.0-only // SPDX-License-Identifier: GPL-3.0-only
use color_eyre::eyre::WrapErr;
use cosmic::app::{Core, Settings, Task}; use cosmic::app::{Core, Settings, Task};
use cosmic::cctk::wayland_protocols::xdg::shell::client::xdg_positioner::Gravity; use cosmic::cctk::wayland_protocols::xdg::shell::client::xdg_positioner::Gravity;
use cosmic::iced::{Point, Rectangle, Size}; use cosmic::iced::{Point, Rectangle, Size};
@ -33,6 +34,9 @@ use std::{
sync::Arc, sync::Arc,
}; };
use tokio::{sync::mpsc, task}; use tokio::{sync::mpsc, task};
use tracing::level_filters::LevelFilter;
use tracing::warn;
use tracing_subscriber::{EnvFilter, fmt, prelude::*};
use wayland_client::{Proxy, protocol::wl_output::WlOutput}; use wayland_client::{Proxy, protocol::wl_output::WlOutput};
use crate::{ use crate::{
@ -47,7 +51,35 @@ fn lockfile_opt() -> Option<PathBuf> {
} }
pub fn main(user: pwd::Passwd) -> Result<(), Box<dyn std::error::Error>> { pub fn main(user: pwd::Passwd) -> Result<(), Box<dyn std::error::Error>> {
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("warn")).init(); color_eyre::install().wrap_err("failed to install color_eyre error handler")?;
let trace = tracing_subscriber::registry();
let env_filter = EnvFilter::builder()
.with_default_directive(LevelFilter::WARN.into())
.from_env_lossy();
#[cfg(feature = "systemd")]
if let Ok(journald) = tracing_journald::layer() {
trace
.with(journald)
.with(env_filter)
.try_init()
.wrap_err("failed to initialize logger")?;
} else {
trace
.with(fmt::layer())
.with(env_filter)
.try_init()
.wrap_err("failed to initialize logger")?;
warn!("failed to connect to journald")
}
#[cfg(not(feature = "systemd"))]
trace
.with(fmt::layer())
.with(env_filter)
.try_init()
.wrap_err("failed to initialize logger")?;
crate::localize::localize(); crate::localize::localize();
@ -74,11 +106,11 @@ pub fn pam_thread(username: String, conversation: Conversation) -> Result<(), pa
let mut context = pam_client::Context::new("cosmic-greeter", Some(&username), conversation)?; let mut context = pam_client::Context::new("cosmic-greeter", Some(&username), conversation)?;
// Authenticate the user (ask for password, 2nd-factor token, fingerprint, etc.) // Authenticate the user (ask for password, 2nd-factor token, fingerprint, etc.)
log::info!("authenticate"); tracing::info!("authenticate");
context.authenticate(pam_client::Flag::NONE)?; context.authenticate(pam_client::Flag::NONE)?;
// Validate the account (is not locked, expired, etc.) // Validate the account (is not locked, expired, etc.)
log::info!("acct_mgmt"); tracing::info!("acct_mgmt");
context.acct_mgmt(pam_client::Flag::NONE)?; context.acct_mgmt(pam_client::Flag::NONE)?;
Ok(()) Ok(())
@ -96,7 +128,7 @@ impl Conversation {
secret: bool, secret: bool,
) -> Result<CString, pam_client::ErrorCode> { ) -> Result<CString, pam_client::ErrorCode> {
let prompt = prompt_c.to_str().map_err(|err| { let prompt = prompt_c.to_str().map_err(|err| {
log::error!("failed to convert prompt to UTF-8: {:?}", err); tracing::error!("failed to convert prompt to UTF-8: {:?}", err);
pam_client::ErrorCode::CONV_ERR pam_client::ErrorCode::CONV_ERR
})?; })?;
@ -108,24 +140,24 @@ impl Conversation {
.await .await
}) })
.map_err(|err| { .map_err(|err| {
log::error!("failed to send prompt: {:?}", err); tracing::error!("failed to send prompt: {:?}", err);
pam_client::ErrorCode::CONV_ERR pam_client::ErrorCode::CONV_ERR
})?; })?;
let value = self.value_rx.blocking_recv().ok_or_else(|| { let value = self.value_rx.blocking_recv().ok_or_else(|| {
log::error!("failed to receive value: channel closed"); tracing::error!("failed to receive value: channel closed");
pam_client::ErrorCode::CONV_ERR pam_client::ErrorCode::CONV_ERR
})?; })?;
CString::new(value).map_err(|err| { CString::new(value).map_err(|err| {
log::error!("failed to convert value to C string: {:?}", err); tracing::error!("failed to convert value to C string: {:?}", err);
pam_client::ErrorCode::CONV_ERR pam_client::ErrorCode::CONV_ERR
}) })
} }
fn message(&mut self, prompt_c: &CStr) -> Result<(), pam_client::ErrorCode> { fn message(&mut self, prompt_c: &CStr) -> Result<(), pam_client::ErrorCode> {
let prompt = prompt_c.to_str().map_err(|err| { let prompt = prompt_c.to_str().map_err(|err| {
log::error!("failed to convert prompt to UTF-8: {:?}", err); tracing::error!("failed to convert prompt to UTF-8: {:?}", err);
pam_client::ErrorCode::CONV_ERR pam_client::ErrorCode::CONV_ERR
})?; })?;
@ -137,7 +169,7 @@ impl Conversation {
.await .await
}) })
.map_err(|err| { .map_err(|err| {
log::error!("failed to send prompt: {:?}", err); tracing::error!("failed to send prompt: {:?}", err);
pam_client::ErrorCode::CONV_ERR pam_client::ErrorCode::CONV_ERR
}) })
} }
@ -145,29 +177,29 @@ impl Conversation {
impl pam_client::ConversationHandler for Conversation { impl pam_client::ConversationHandler for Conversation {
fn prompt_echo_on(&mut self, prompt_c: &CStr) -> Result<CString, pam_client::ErrorCode> { fn prompt_echo_on(&mut self, prompt_c: &CStr) -> Result<CString, pam_client::ErrorCode> {
log::info!("prompt_echo_on {:?}", prompt_c); tracing::info!("prompt_echo_on {:?}", prompt_c);
self.prompt_value(prompt_c, false) self.prompt_value(prompt_c, false)
} }
fn prompt_echo_off(&mut self, prompt_c: &CStr) -> Result<CString, pam_client::ErrorCode> { fn prompt_echo_off(&mut self, prompt_c: &CStr) -> Result<CString, pam_client::ErrorCode> {
log::info!("prompt_echo_off {:?}", prompt_c); tracing::info!("prompt_echo_off {:?}", prompt_c);
self.prompt_value(prompt_c, true) self.prompt_value(prompt_c, true)
} }
fn text_info(&mut self, prompt_c: &CStr) { fn text_info(&mut self, prompt_c: &CStr) {
log::info!("text_info {:?}", prompt_c); tracing::info!("text_info {:?}", prompt_c);
match self.message(prompt_c) { match self.message(prompt_c) {
Ok(()) => (), Ok(()) => (),
Err(err) => { Err(err) => {
log::warn!("failed to send text_info: {:?}", err); tracing::warn!("failed to send text_info: {:?}", err);
} }
} }
} }
fn error_msg(&mut self, prompt_c: &CStr) { fn error_msg(&mut self, prompt_c: &CStr) {
//TODO: treat error type differently? //TODO: treat error type differently?
log::info!("error_msg {:?}", prompt_c); tracing::info!("error_msg {:?}", prompt_c);
match self.message(prompt_c) { match self.message(prompt_c) {
Ok(()) => (), Ok(()) => (),
Err(err) => { Err(err) => {
log::warn!("failed to send error_msg: {:?}", err); tracing::warn!("failed to send error_msg: {:?}", err);
} }
} }
} }
@ -226,7 +258,7 @@ impl Drop for State {
fn drop(&mut self) { fn drop(&mut self) {
// Abort the locked task when the state is changed. // Abort the locked task when the state is changed.
if let Self::Locked { task_handle } = self { if let Self::Locked { task_handle } = self {
log::info!("dropping lockscreen tasks"); tracing::info!("dropping lockscreen tasks");
task_handle.abort(); task_handle.abort();
} }
} }
@ -542,7 +574,7 @@ impl cosmic::Application for App {
let task = if cfg!(feature = "logind") { let task = if cfg!(feature = "logind") {
if already_locked { if already_locked {
// Recover previously locked state // Recover previously locked state
log::info!("recovering previous locked state"); tracing::info!("recovering previous locked state");
app.state = State::Locking; app.state = State::Locking;
lock() lock()
} else { } else {
@ -551,7 +583,7 @@ impl cosmic::Application for App {
} }
} else { } else {
// When logind feature not used, lock immediately // When logind feature not used, lock immediately
log::info!("locking immediately"); tracing::info!("locking immediately");
app.state = State::Locking; app.state = State::Locking;
lock() lock()
}; };
@ -569,7 +601,7 @@ impl cosmic::Application for App {
Message::OutputEvent(output_event, output) => { Message::OutputEvent(output_event, output) => {
match output_event { match output_event {
OutputEvent::Created(output_info_opt) => { OutputEvent::Created(output_info_opt) => {
log::info!("output {}: created", output.id()); tracing::info!("output {}: created", output.id());
let surface_id = SurfaceId::unique(); let surface_id = SurfaceId::unique();
let subsurface_id = SurfaceId::unique(); let subsurface_id = SurfaceId::unique();
@ -578,7 +610,7 @@ impl cosmic::Application for App {
self.common.surface_ids.insert(output.clone(), surface_id) self.common.surface_ids.insert(output.clone(), surface_id)
{ {
//TODO: remove old surface? //TODO: remove old surface?
log::warn!( tracing::warn!(
"output {}: already had surface ID {:?}", "output {}: already had surface ID {:?}",
output.id(), output.id(),
old_surface_id old_surface_id
@ -614,11 +646,11 @@ impl cosmic::Application for App {
.insert(output_name.clone(), text_input_id.clone()); .insert(output_name.clone(), text_input_id.clone());
} }
None => { None => {
log::warn!("output {}: no output name", output.id()); tracing::warn!("output {}: no output name", output.id());
} }
}, },
None => { None => {
log::warn!("output {}: no output info", output.id()); tracing::warn!("output {}: no output info", output.id());
} }
} }
@ -672,7 +704,7 @@ impl cosmic::Application for App {
} }
} }
OutputEvent::Removed => { OutputEvent::Removed => {
log::info!("output {}: removed", output.id()); tracing::info!("output {}: removed", output.id());
match self.common.surface_ids.remove(&output) { match self.common.surface_ids.remove(&output) {
Some(surface_id) => { Some(surface_id) => {
self.common.surface_images.remove(&surface_id); self.common.surface_images.remove(&surface_id);
@ -686,7 +718,7 @@ impl cosmic::Application for App {
} }
} }
None => { None => {
log::warn!("output {}: no surface found", output.id()); tracing::warn!("output {}: no surface found", output.id());
} }
} }
} }
@ -711,14 +743,14 @@ impl cosmic::Application for App {
.subsurface_rects .subsurface_rects
.insert(output.clone(), Rectangle::new(loc, sub_size)); .insert(output.clone(), Rectangle::new(loc, sub_size));
log::info!("output {}: info update", output.id()); tracing::info!("output {}: info update", output.id());
} }
} }
} }
Message::SessionLockEvent(session_lock_event) => match session_lock_event { Message::SessionLockEvent(session_lock_event) => match session_lock_event {
SessionLockEvent::Focused(..) => {} SessionLockEvent::Focused(..) => {}
SessionLockEvent::Locked => { SessionLockEvent::Locked => {
log::info!("session locked"); tracing::info!("session locked");
if matches!(self.state, State::Locked { .. }) { if matches!(self.state, State::Locked { .. }) {
return Task::none(); return Task::none();
} }
@ -764,7 +796,7 @@ impl cosmic::Application for App {
match pam_res { match pam_res {
Ok(()) => { Ok(()) => {
log::info!("successfully authenticated"); tracing::info!("successfully authenticated");
msg_tx msg_tx
.send(cosmic::Action::App(Message::Unlock)) .send(cosmic::Action::App(Message::Unlock))
.await .await
@ -772,7 +804,7 @@ impl cosmic::Application for App {
break; break;
} }
Err(err) => { Err(err) => {
log::warn!("authentication error: {}", err); tracing::warn!("authentication error: {}", err);
msg_tx msg_tx
.send(cosmic::Action::App(Message::Error( .send(cosmic::Action::App(Message::Error(
err.to_string(), err.to_string(),
@ -838,13 +870,13 @@ impl cosmic::Application for App {
cosmic::app::Action::Surface(msg), cosmic::app::Action::Surface(msg),
))); )));
} else { } else {
log::error!("no rectangle for subsurface..."); tracing::error!("no rectangle for subsurface...");
} }
} }
return Task::batch(commands); return Task::batch(commands);
} }
SessionLockEvent::Unlocked => { SessionLockEvent::Unlocked => {
log::info!("session unlocked"); tracing::info!("session unlocked");
self.state = State::Unlocked; self.state = State::Unlocked;
let mut commands = Vec::new(); let mut commands = Vec::new();
@ -883,7 +915,7 @@ impl cosmic::Application for App {
} }
Message::Inhibit(inhibit) => match self.state { Message::Inhibit(inhibit) => match self.state {
State::Locked { .. } => { State::Locked { .. } => {
log::info!("no need to inhibit sleep when already locked"); tracing::info!("no need to inhibit sleep when already locked");
} }
_ => { _ => {
self.inhibit_opt = Some(inhibit); self.inhibit_opt = Some(inhibit);
@ -910,14 +942,14 @@ impl cosmic::Application for App {
Message::Channel(value_tx) Message::Channel(value_tx)
}); });
} }
None => log::warn!("tried to submit when value_tx_opt not set"), None => tracing::warn!("tried to submit when value_tx_opt not set"),
} }
} }
Message::Suspend => { Message::Suspend => {
#[cfg(feature = "logind")] #[cfg(feature = "logind")]
return cosmic::Task::future(async move { crate::logind::suspend().await.err() }) return cosmic::Task::future(async move { crate::logind::suspend().await.err() })
.and_then(|err| { .and_then(|err| {
log::error!("failed to suspend: {:?}", err); tracing::error!("failed to suspend: {:?}", err);
cosmic::task::message(cosmic::Action::App(Message::Error(err.to_string()))) cosmic::task::message(cosmic::Action::App(Message::Error(err.to_string())))
}); });
} }
@ -929,7 +961,7 @@ impl cosmic::Application for App {
} }
Message::Lock => match self.state { Message::Lock => match self.state {
State::Unlocked => { State::Unlocked => {
log::info!("session locking"); tracing::info!("session locking");
self.state = State::Locking; self.state = State::Locking;
// Clear errors // Clear errors
self.common.error_opt = None; self.common.error_opt = None;
@ -938,23 +970,23 @@ impl cosmic::Application for App {
// Try to create lockfile when locking // Try to create lockfile when locking
if let Some(ref lockfile) = self.flags.lockfile_opt { if let Some(ref lockfile) = self.flags.lockfile_opt {
if let Err(err) = fs::File::create(lockfile) { if let Err(err) = fs::File::create(lockfile) {
log::warn!("failed to create lockfile {:?}: {}", lockfile, err); tracing::warn!("failed to create lockfile {:?}: {}", lockfile, err);
} }
} }
// Tell compositor to lock // Tell compositor to lock
return lock(); return lock();
} }
State::Unlocking => { State::Unlocking => {
log::info!("session still unlocking"); tracing::info!("session still unlocking");
} }
State::Locking | State::Locked { .. } => { State::Locking | State::Locked { .. } => {
log::info!("session already locking or locked"); tracing::info!("session already locking or locked");
} }
}, },
Message::Unlock => { Message::Unlock => {
match self.state { match self.state {
State::Locked { .. } => { State::Locked { .. } => {
log::info!("sessing unlocking"); tracing::info!("sessing unlocking");
self.state = State::Unlocking; self.state = State::Unlocking;
// Clear errors // Clear errors
self.common.error_opt = None; self.common.error_opt = None;
@ -963,7 +995,7 @@ impl cosmic::Application for App {
// Try to delete lockfile when unlocking // Try to delete lockfile when unlocking
if let Some(ref lockfile) = self.flags.lockfile_opt { if let Some(ref lockfile) = self.flags.lockfile_opt {
if let Err(err) = fs::remove_file(lockfile) { if let Err(err) = fs::remove_file(lockfile) {
log::warn!("failed to remove lockfile {:?}: {}", lockfile, err); tracing::warn!("failed to remove lockfile {:?}: {}", lockfile, err);
} }
} }
@ -983,10 +1015,10 @@ impl cosmic::Application for App {
return Task::batch(commands); return Task::batch(commands);
} }
State::Locking => { State::Locking => {
log::info!("session still locking"); tracing::info!("session still locking");
} }
State::Unlocking | State::Unlocked => { State::Unlocking | State::Unlocked => {
log::info!("session already unlocking or unlocked"); tracing::info!("session already unlocking or unlocked");
} }
} }
} }
@ -1032,7 +1064,7 @@ impl cosmic::Application for App {
) )
.map(|res| { .map(|res| {
if !res.errors.is_empty() { if !res.errors.is_empty() {
log::info!("errors loading background state: {:?}", res.errors); tracing::info!("errors loading background state: {:?}", res.errors);
} }
Message::BackgroundState(res.config) Message::BackgroundState(res.config)
}), }),
@ -1047,7 +1079,7 @@ impl cosmic::Application for App {
) )
.map(|res| { .map(|res| {
if !res.errors.is_empty() { if !res.errors.is_empty() {
log::info!("errors loading background state: {:?}", res.errors); tracing::info!("errors loading background state: {:?}", res.errors);
} }
Message::TimeAppletConfig(res.config) Message::TimeAppletConfig(res.config)
}), }),

View file

@ -52,7 +52,7 @@ pub fn subscription() -> Subscription<Message> {
match handler(&mut msg_tx).await { match handler(&mut msg_tx).await {
Ok(()) => {} Ok(()) => {}
Err(err) => { Err(err) => {
log::warn!("logind error: {}", err); tracing::warn!("logind error: {}", err);
//TODO: send error //TODO: send error
} }
} }
@ -89,13 +89,13 @@ pub async fn handler(msg_tx: &mut mpsc::Sender<Message>) -> Result<(), Box<dyn E
Some(signal) => match signal.args() { Some(signal) => match signal.args() {
Ok(args) => { Ok(args) => {
if args.start { if args.start {
log::info!("logind prepare for sleep"); tracing::info!("logind prepare for sleep");
if let Some(inhibit) = inhibit_opt.take() { if let Some(inhibit) = inhibit_opt.take() {
msg_tx.send(Message::Inhibit(Arc::new(inhibit))).await?; msg_tx.send(Message::Inhibit(Arc::new(inhibit))).await?;
} }
msg_tx.send(Message::Lock).await?; msg_tx.send(Message::Lock).await?;
} else { } else {
log::info!("logind resume"); tracing::info!("logind resume");
if inhibit_opt.is_none() { if inhibit_opt.is_none() {
inhibit_opt = Some(inhibit(&manager).await?); inhibit_opt = Some(inhibit(&manager).await?);
} }
@ -104,19 +104,19 @@ pub async fn handler(msg_tx: &mut mpsc::Sender<Message>) -> Result<(), Box<dyn E
} }
}, },
Err(err) => { Err(err) => {
log::warn!("logind prepare to sleep invalid data: {}", err); tracing::warn!("logind prepare to sleep invalid data: {}", err);
} }
}, },
None => { None => {
log::warn!("logind prepare to sleep missing data"); tracing::warn!("logind prepare to sleep missing data");
} }
} }
}, },
_ = lock.next() => { _ = lock.next() => {
log::info!("logind lock"); tracing::info!("logind lock");
msg_tx.send(Message::Lock).await?; msg_tx.send(Message::Lock).await?;
}, _ = unlock.next() => { }, _ = unlock.next() => {
log::info!("logind unlock"); tracing::info!("logind unlock");
msg_tx.send(Message::Unlock).await?; msg_tx.send(Message::Unlock).await?;
}); });

View file

@ -42,7 +42,7 @@ pub fn subscription() -> Subscription<Option<&'static str>> {
match handler(&mut msg_tx).await { match handler(&mut msg_tx).await {
Ok(()) => {} Ok(()) => {}
Err(err) => { Err(err) => {
log::warn!("networkmanager error: {}", err); tracing::warn!("networkmanager error: {}", err);
//TODO: send error //TODO: send error
} }
} }

View file

@ -47,7 +47,7 @@ impl Time {
let locale = match get_local() { let locale = match get_local() {
Ok(locale) => locale, Ok(locale) => locale,
Err(e) => { Err(e) => {
log::error!("can't get locale {e}"); tracing::error!("can't get locale {e}");
Locale::default() Locale::default()
} }
}; };
@ -136,7 +136,7 @@ pub fn tz_updates() -> Task<chrono_tz::Tz> {
Task::stream(async_fn_stream::fn_stream(|emitter| async move { Task::stream(async_fn_stream::fn_stream(|emitter| async move {
loop { loop {
if let Err(err) = tz_stream(&emitter).await { if let Err(err) = tz_stream(&emitter).await {
log::error!("{err:?}"); tracing::error!("{err:?}");
} }
_ = time::sleep(Duration::from_secs(60)).await; _ = time::sleep(Duration::from_secs(60)).await;
} }

View file

@ -15,7 +15,7 @@ pub fn subscription() -> Subscription<Option<(String, f64)>> {
match handler(&mut msg_tx).await { match handler(&mut msg_tx).await {
Ok(()) => {} Ok(()) => {}
Err(err) => { Err(err) => {
log::warn!("upower error: {}", err); tracing::warn!("upower error: {}", err);
//TODO: send error //TODO: send error
} }
} }