page layout tool
git clone https://git.lucas.co/cce-layout-interface.git
refactor: modernize and systematize workspace logging
Cargo.toml | 4 ++++
Makefile | 2 +-
src/main.rs | 20 ++++++++++++--------
3 files changed, 17 insertions(+), 9 deletions(-)
diff --git a/Cargo.toml b/Cargo.toml
index 87e29cb..a7e412c 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -18,4 +18,8 @@ glyphon = "0.8"
tokio = { version = "1", features = ["full"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
+log = "0.4"
+env_logger = "0.11"
+
+
diff --git a/Makefile b/Makefile
index ef7437c..5f9f463 100644
--- a/Makefile
+++ b/Makefile
@@ -5,7 +5,7 @@ build:
install: build
mkdir -p ~/.local/bin
- install -m 755 target/release/clear-layout-interface ~/.local/bin/clear-layout-interface
+ install -m 755 ../target/release/clear-layout-interface ~/.local/bin/clear-layout-interface
run:
cargo run
diff --git a/src/main.rs b/src/main.rs
index 341c7f9..7c4b39c 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -520,9 +520,9 @@ impl LayoutApp {
if let Some(path) = path_opt {
if let Err(e) = self.save_document(&path) {
- eprintln!("ERROR: Failed to save document: {}", e);
+ log::error!("Failed to save document: {}", e);
} else {
- println!("DEBUG: Successfully saved layout to {:?}", path);
+ log::info!("Successfully saved layout to {:?}", path);
self.current_file_path = Some(path.clone());
self.last_saved_document = self.get_current_document();
self.add_recent_file(path);
@@ -626,9 +626,9 @@ impl LayoutApp {
self.pan_x = 0.0;
self.pan_y = 0.0;
if let Err(e) = self.load_document(&path) {
- eprintln!("ERROR: Failed to load document: {}", e);
+ log::error!("Failed to load document: {}", e);
} else {
- println!("DEBUG: Successfully loaded layout from {:?}", path);
+ log::info!("Successfully loaded layout from {:?}", path);
self.current_file_path = Some(path.clone());
self.last_saved_document = self.get_current_document();
self.add_recent_file(path);
@@ -2903,9 +2903,9 @@ impl Application for LayoutApp {
AppMessage::Save => {
if let Some(ref path) = self.current_file_path {
if let Err(e) = self.save_document(path) {
- eprintln!("ERROR: Failed to save document: {}", e);
+ log::error!("Failed to save document: {}", e);
} else {
- println!("DEBUG: Successfully saved layout to {:?}", path);
+ log::info!("Successfully saved layout to {:?}", path);
self.last_saved_document = self.get_current_document();
self.add_recent_file(path.clone());
}
@@ -3604,9 +3604,9 @@ impl Application for LayoutApp {
self.pan_x = 0.0;
self.pan_y = 0.0;
if let Err(e) = self.load_document(&path) {
- eprintln!("ERROR: Failed to load document: {}", e);
+ log::error!("Failed to load document: {}", e);
} else {
- println!("DEBUG: Successfully loaded layout from {:?}", path);
+ log::info!("Successfully loaded layout from {:?}", path);
self.current_file_path = Some(path.clone());
self.last_saved_document = self.get_current_document();
self.add_recent_file(path);
@@ -3828,6 +3828,10 @@ impl Application for LayoutApp {
}
fn main() {
+ env_logger::Builder::from_default_env()
+ .filter_level(log::LevelFilter::Info)
+ .init();
+
let rt = tokio::runtime::Runtime::new().expect("tokio runtime");
let _guard = rt.enter();