Skip to content
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

Merged
merged 4 commits into from
Sep 4, 2019
Merged

Use logging crate #135

merged 4 commits into from
Sep 4, 2019

Conversation

LiHRaM
Copy link
Collaborator

@LiHRaM LiHRaM commented Aug 31, 2019

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:

  • Replace calls to println and eprintln with appropriate logging macros
  • Add example with logging impl

Copy link
Member

@cmyr cmyr left a 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!

@@ -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");
Copy link
Member

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.

@@ -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()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I vote debug!.

@@ -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!(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

@@ -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);
Copy link
Member

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!

Copy link
Collaborator Author

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. 😄

@@ -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);
Copy link
Member

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe debug!?

// 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};
Copy link
Member

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.

Copy link
Collaborator Author

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.

Copy link
Member

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. 👍

@@ -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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warn! I think.

@@ -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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warn! I think?

@@ -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);
Copy link
Member

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!.

Copy link
Member

@cmyr cmyr left a 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]
Copy link
Member

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?

Copy link
Collaborator Author

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

true
}
}
// Copyright 2018 The xi-editor Authors.
Copy link
Member

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..

use simple_logger;

fn main() {
simple_logger::init().unwrap();
Copy link
Member

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)

Copy link
Collaborator Author

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
Copy link
Member

@cmyr cmyr left a 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!

@cmyr cmyr merged commit 90ee2e6 into master Sep 4, 2019
@cmyr cmyr deleted the logging branch September 4, 2019 06:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add logging
2 participants