Skip to content
This repository was archived by the owner on Jun 8, 2021. It is now read-only.

Support for logging through the log crate #658

Closed
xanathar opened this issue Jul 2, 2020 · 8 comments
Closed

Support for logging through the log crate #658

xanathar opened this issue Jul 2, 2020 · 8 comments

Comments

@xanathar
Copy link
Contributor

xanathar commented Jul 2, 2020

Hi,
searching for a solution to integrate a Rust project with glib logging, I stumbled on the glib_logger project, which bridges glib logging with the log crate.

Since it didn't have full support for domains and other features I was interested in, I sent a PR (still pending) which adds the missing bits.

However, I was wondering if there is an interest in adopting such a solution in the main gtk-rs sources, given that logging is quite a basic functionality which pretty much all glib applications need, and that this is a fair solution at being as idiomatic as possible while still integrating with glib log handlers.

Would a PR for this be welcome (in which project) or not?
Or, in general, your thoughts?

@sdroege
Copy link
Member

sdroege commented Jul 2, 2020

I think having integration into the log crate into both directions would be useful to have in the glib bindings (glib is the repo you want to create the PR for), but it should be hidden behind a feature flag.

@xanathar
Copy link
Contributor Author

xanathar commented Jul 3, 2020

Cool thanks, I'll send a contribution as soon as I can.
(you can close this issue or keep it open until the pr, as you prefer)

@sdroege
Copy link
Member

sdroege commented Sep 21, 2020

Now the only other thing that would be useful to have is a GLib logging function that directly calls into the log crate instead of doing its own stuff. Then we have integration in either direction, and that one is actually more useful for most of my code :)

@xanathar
Copy link
Contributor Author

I can do that, but it will take a little more time.

@sdroege
Copy link
Member

sdroege commented Sep 22, 2020

No worries :)

@xanathar
Copy link
Contributor Author

xanathar commented Oct 12, 2020

I've done this... but it's very very minimal:

fn default_glib_log_handler(string1: &str, level: glib::LogLevel, string2: &str) {
    let level = match level {
        glib::LogLevel::Error | glib::LogLevel::Critical => log::Level::Error,
        glib::LogLevel::Warning => log::Level::Warn,
        glib::LogLevel::Message | glib::LogLevel::Info => log::Level::Info,
        glib::LogLevel::Debug => log::Level::Debug,
    };

    log!(target: string1, level, "{}", string2);
}

fn main() {
    glib::log_set_default_handler(default_glib_log_handler);
    ...
}

I don't even know if it's worth adding to the glib-rs library, given that it's such small snippet (though I can easily send a PR for that).

Did you have in mind something with a bigger scope?

@sdroege
Copy link
Member

sdroege commented Oct 12, 2020

Did you have in mind something with a bigger scope?

No, exactly that. It's not very complicated but it's boring to copy such a thing from project to project :)

@xanathar
Copy link
Contributor Author

Ok, I'll send a PR very soon, then :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants