-
Notifications
You must be signed in to change notification settings - Fork 569
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use logging crate #135
Use logging crate #135
Conversation
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.
Awesome, thanks for this; definitely something I've wanted and have been avoiding getting around to, so very much appreciated!
have some little notes on logging levels and a thought on your example, but overall very happy for this work!
druid-shell/src/mac/mod.rs
Outdated
@@ -204,7 +206,7 @@ lazy_static! { | |||
} | |||
decl.add_method(sel!(dealloc), dealloc as extern "C" fn(&Object, Sel)); | |||
extern "C" fn dealloc(this: &Object, _sel: Sel) { | |||
eprintln!("view is dealloc'ed"); | |||
error!("view is dealloc'ed"); |
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 this is just info
, deallocation is part of normal program execution.
src/localization.rs
Outdated
@@ -149,7 +151,7 @@ impl ResourceManager { | |||
/// Return the best localization bundle for the provided `LanguageIdentifier`. | |||
fn get_bundle(&mut self, locale: &LanguageIdentifier, resource_ids: &[String]) -> BundleStack { | |||
let resolved_locales = self.resolve_locales(locale.clone()); | |||
eprintln!("resolved: {}", PrintLocales(resolved_locales.as_slice())); | |||
info!("resolved: {}", PrintLocales(resolved_locales.as_slice())); |
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 vote debug!
.
src/localization.rs
Outdated
@@ -213,7 +215,7 @@ impl L10nManager { | |||
.parse() | |||
.unwrap_or_else(|_| default_locale.clone()); | |||
let locales = get_available_locales(base_dir).unwrap_or_default(); | |||
eprintln!( | |||
info!( |
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.
ditto
src/localization.rs
Outdated
@@ -265,7 +267,7 @@ impl L10nManager { | |||
.current_bundle | |||
.format_pattern(key, value, args, &mut errs); | |||
for err in errs { | |||
eprintln!("localization error {:?}", err); | |||
error!("localization error {:?}", err); |
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 vote warn!
. This is tricky; but basically error!
is the highest log level we have, and should probably be reserved for things that are fatal or otherwise compromise the execution of the application. This is maybe an error though, it's hard to say. I think that this summary is a reasonable overview of how to think about the different log levels, this is definitely a 'feel' thing, though!
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.
Yeah. I just ventured a guess with most of them, but didn't feel familiar enough with the internals of the library in a lot of cases. Thanks for taking the time. 😄
src/widget/textbox.rs
Outdated
@@ -193,11 +195,11 @@ impl TextBox { | |||
|
|||
// TODO: waiting on druid clipboard support for copy / paste. | |||
fn copy_text(&self, input: String) { | |||
eprintln!("COPY: {}", input); | |||
error!("COPY: {}", input); |
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'd go with warn!
, and change the message to indicate this is not implemented. 👍
src/lib.rs
Outdated
@@ -764,7 +766,7 @@ impl<T: Data + 'static> WinHandler for UiMain<T> { | |||
} | |||
|
|||
fn command(&mut self, id: u32, ctx: &mut dyn WinCtx) { | |||
eprintln!("got command {}", id); | |||
error!("got command {}", id); |
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.
maybe debug!
?
examples/logging.rs
Outdated
// Typically the user would use a crate for logging | ||
// Here we implement the Log trait for a struct and print everything to STDOUT | ||
// See https://docs.rs/log/ for more info | ||
use log::{Level, Metadata, Record}; |
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 appreciate the thoroughness, but I wonder if this isn't out of scope for this PR?
What I would personally be inclined to do is to find the simplest, most minimal logging crate ([simple_logger]](https://github.com/borntyping/rust-simple_logger) was the best i could find in a quick search) and just use that? It's closer to what the user will ever actually do.
Something we might consider for follow-up work is to add something like this to druid itself, and then we could let the user ask for stderr logging when they start the runloop.
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 wrote it like that to avoid any extra dependencies. Little did I know about this...
So I added it as a dev-dependency.
Anyway, sounds good. I'll leave more concrete logging implications on the druid library up to another PR.
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.
yea, dev dependency is perfect. 👍
druid-shell/src/windows/mod.rs
Outdated
@@ -513,7 +515,7 @@ impl WndProc for MyWndProc { | |||
let text = match s.stashed_char { | |||
Some(c) => c, | |||
None => { | |||
eprintln!("failed to convert WM_CHAR to char: {:#X}", wparam); | |||
error!("failed to convert WM_CHAR to char: {:#X}", wparam); |
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.
warn!
I think.
druid-shell/src/windows/mod.rs
Outdated
@@ -865,7 +867,7 @@ impl WindowBuilder { | |||
} | |||
|
|||
let dcomp_state = create_dcomp_state(self.present_strategy, hwnd).unwrap_or_else(|e| { | |||
println!("Error creating swapchain, falling back to hwnd: {:?}", e); | |||
error!("Error creating swapchain, falling back to hwnd: {:?}", e); |
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.
warn!
I think?
druid-shell/src/windows/mod.rs
Outdated
@@ -930,9 +932,9 @@ unsafe fn create_dcomp_state( | |||
&IID_IDXGIFactory2, | |||
&mut factory as *mut *mut IDXGIFactory2 as *mut *mut c_void, | |||
))?; | |||
println!("dxgi factory pointer = {:?}", factory); | |||
info!("dxgi factory pointer = {:?}", factory); |
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.
these can all be debug!
.
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.
Awesome, thanks. A few more little things but this looks good.
Cargo.toml
Outdated
@@ -1,27 +1,31 @@ | |||
[package] |
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.
do you have any idea why this is showing all these changes? Did the encoding change or something??
edit: looked into this, and it's a different line ending?
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.
Weird. My git settings should be enforcing LF. Sorry about that
src/widget/null.rs
Outdated
true | ||
} | ||
} | ||
// Copyright 2018 The xi-editor Authors. |
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.
ditto here, something confusing is going on. I wonder if it's just the diff is screwing up..
examples/logging.rs
Outdated
use simple_logger; | ||
|
||
fn main() { | ||
simple_logger::init().unwrap(); |
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 actually think we can get rid of this file, but I would like to add logging to a few examples; in particular hello
, calc
, and custom_widget
. (These are the examples I mostly use when experimenting & debugging)
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.
Fair enough. ;) I've added logging to those examples.
Added logging to three other examples instead
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.
Awesome, thanks for this @LiHRaM!
fixes #99
Looking to start contributing again, thought this might be a nice place to start.
I've added logging using the
log
crate.Todo: