mirror of
https://github.com/JakeStanger/ironbar.git
synced 2024-11-22 05:34:35 +03:00
feat: route gtk logging through tracing
Yay consistent logging, especially now the tray uses a library that likes to vomit warnings
This commit is contained in:
parent
5afe5c19b9
commit
e1f3b1bb72
@ -1,8 +1,9 @@
|
||||
use color_eyre::Result;
|
||||
use dirs::data_dir;
|
||||
use glib::{LogLevel, LogWriterOutput};
|
||||
use std::{env, panic};
|
||||
use strip_ansi_escapes::Writer;
|
||||
use tracing::error;
|
||||
use tracing::{debug, error, info, warn};
|
||||
use tracing_appender::non_blocking::{NonBlocking, WorkerGuard};
|
||||
use tracing_appender::rolling::Rotation;
|
||||
use tracing_error::ErrorLayer;
|
||||
@ -89,5 +90,33 @@ fn install_tracing() -> Result<WorkerGuard> {
|
||||
)
|
||||
.init();
|
||||
|
||||
glib::log_set_writer_func(|level, fields| {
|
||||
const KEY_DOMAIN: &str = "GLIB_DOMAIN";
|
||||
const KEY_MESSAGE: &str = "MESSAGE";
|
||||
|
||||
let domain = fields
|
||||
.iter()
|
||||
.find(|f| f.key() == KEY_DOMAIN)
|
||||
.and_then(|f| f.value_str())
|
||||
.unwrap_or("Glib Unknown");
|
||||
|
||||
let message = fields
|
||||
.iter()
|
||||
.find(|f| f.key() == KEY_MESSAGE)
|
||||
.and_then(|f| f.value_str())
|
||||
.unwrap_or_default();
|
||||
|
||||
match level {
|
||||
LogLevel::Error => error!(target: "GTK", "[{domain}] {message}"),
|
||||
LogLevel::Critical => error!(target: "GTK", "[{domain}] CRITICAL: {message}"),
|
||||
LogLevel::Warning => warn!(target: "GTK", "[{domain}] {message}"),
|
||||
LogLevel::Message => info!(target: "GTK", "[{domain}] MESSAGE: {message}"),
|
||||
LogLevel::Info => info!(target: "GTK", "[{domain}] MESSAGE: {message}"),
|
||||
LogLevel::Debug => debug!(target: "GTK", "[{domain}] {message}"),
|
||||
}
|
||||
|
||||
LogWriterOutput::Handled
|
||||
});
|
||||
|
||||
Ok(guard)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user