-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* introduce logger * add support for aborting task * add auto-scroll to console * refactor LogConsole as separate component * add rotating esp-rs logo to Rust installation * add esp-prog picture for monitoring * bump up version to 0.0.13
- Loading branch information
Showing
19 changed files
with
496 additions
and
382 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
|
||
use tauri::Window; | ||
use tauri::Manager; | ||
use log::{ Log, Record, Metadata }; | ||
|
||
#[derive(Clone, serde::Serialize)] | ||
struct ConsoleEvent { | ||
message: String, | ||
} | ||
|
||
pub struct TauriLogger { | ||
window: Window, | ||
} | ||
|
||
impl TauriLogger { | ||
pub fn new(window: Window) -> Self { | ||
Self { window } | ||
} | ||
} | ||
|
||
impl Log for TauriLogger { | ||
fn enabled(&self, _metadata: &Metadata) -> bool { | ||
true | ||
} | ||
|
||
fn log(&self, record: &Record) { | ||
if self.enabled(record.metadata()) { | ||
let event = ConsoleEvent { | ||
message: format!("{}", record.args()), | ||
}; | ||
self.window.emit("rust-console", &event).unwrap(); | ||
println!("{}", record.args()); // Also log to stdout | ||
} | ||
} | ||
|
||
fn flush(&self) {} | ||
} | ||
|
||
use fern::Dispatch; | ||
use log::LevelFilter; | ||
|
||
pub fn setup_logging(app: &tauri::App) { | ||
if let Some(window) = app.get_window("main") { | ||
let tauri_logger = TauriLogger::new(window); | ||
|
||
// Set the TauriLogger as the global logger. | ||
log::set_boxed_logger(Box::new(tauri_logger)).expect("Failed to set logger"); | ||
log::set_max_level(log::LevelFilter::Info); // Set max level of logging | ||
|
||
// Fern setup for stdout logging | ||
let _ = Dispatch::new() | ||
.chain(std::io::stdout()) | ||
.level(LevelFilter::Info) // Set desired log level here | ||
.apply(); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.