-
-
Notifications
You must be signed in to change notification settings - Fork 62
Proposal: support for logging through the log crate #694
Conversation
I like this in principle, will review tomorrow :) I wanted to have this in glib since a while.
This is confusing me a bit. How does that differ from |
Two ways mainly:
As I said, those are the most opinionated part. |
src/bridged_logging.rs
Outdated
/// Logs will use the specified domain for logging. Note that this option | ||
/// due to the way the `log` crate is implemented, is global for all crates | ||
/// in the current process. | ||
Custom(&'static str), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this really useful?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm on the fence here.
On one side I assume there will be somebody who wants to add a Rust library to an existing glib based project and is happy to specify a single domain for all Rust logging; on the other they can get a better more future-proof result with a little more effort specifying a domain everywhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know, @GuillaumeGomez ? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's a good idea. However, a static str
might be too restrictive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Must be either that or a String
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fear a String
cannot be done (at the very least not without some dirty tricks), because the logger is a &'static
and, as far as I can tell, there is no way to build a static String
(all its constructors are not const fn
).
Possible workarounds are with a lazy_static
or with a RefCell
inside the logger, but at that point I fear it becomes dirtier and harder to use correctly vs the potential gains.
(disclaimer: limited knowledge of Rust here, so I might be missing something)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could use set_boxed_logger()
but I agree that it's a bit ugly.
So what would be the use-case for this custom string, how would one use it and isn't it confusing to just have everything going into the log
crate showing up the same way in the glib logs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My 2 cents given the current state: let's remove this option, move forward with the rest and eventually add it in the future in another pr if and when any reasonable need+solution comes up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good to me :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good to me as well.
Looks good to me generally |
Sorry I mistakenly closed the PR. Undid the action, but sorry for the noise. |
CI failures seem to be related to formatting. I will fix them by today, along with a couple of docs comments which are not accurate after the latest changes, and I will undraft this. Open questions:
|
I don't see its point personally, but maybe someone else does? :)
I like them and just want a second opinion. |
I like the macros too. :) |
It looks like the macros disappeared from the changes somehow? |
Looks good to me otherwise |
You told me to do a second separate commit... so I removed them and adding them later in a new commit. Have I misunderstood what you wanted ? |
A separate commit in this PR. It's a separate functional change, so should be a separate commit but it can be part of the same PR as it's related. Personally I would also clean up the commit history of this PR so it doesn't contain all the back and forth but just a clean history but I guess we can forget that for the gtk repository anyway :) |
My github-fu is a bit lacking, but I might have done it without accidentally closing the PR like I did last time 😅 |
Looks good to me, thanks a lot :) git is definitely not easy |
Thanks to you :) |
Changed the code with all the suggestions collected so far. |
I've clarified the usage in documentation, fixed the code examples and added the new features to Travis' CI (hoping it gets green :) ). |
CI seems happy :) Thanks! |
This PR is (as now) more meant as a base for discussion rather than something meant to be merged (though, in case, it's tested and somewhat ready).
This is a follow-up to this issue: #658
The changes contain:
GlibLogger
struct implementing thelog::Log
trait, so that code using the log crate will log to glib automatically (with customizable behavior)G_LOG_DOMAIN
static/constThe two parts above are "activated" by two different features in
Cargo.toml
:bridged_logging
andbridged_logging_domain_macros
.I understand these are probably a bit "opinionated" in their implementation, so feedback is welcome; probably the most controversial part could be the overridden macros: if those are an obstacle they can be removed and only the adapter kept.
I think a sizable part of people interfacing glib code with Rust code using gtk-rs will want to have the two logging systems cooperating; currently this is done by custom code or external third party crates, so this might be helpful.
Example code using this, would be: