about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBaitinq <manuelpalenzuelamerino@gmail.com>2022-11-06 01:29:45 +0100
committerBaitinq <manuelpalenzuelamerino@gmail.com>2022-11-06 01:29:49 +0100
commitf73c32eea7d421ad17f69b0a174456554bc580f1 (patch)
tree8641a36ffe5a35e13a0a0a9abd0faa2262320094
parentReadme: Improve run instructions with frontend auto-open (diff)
downloadOSSE-f73c32eea7d421ad17f69b0a174456554bc580f1.tar.gz
OSSE-f73c32eea7d421ad17f69b0a174456554bc580f1.tar.bz2
OSSE-f73c32eea7d421ad17f69b0a174456554bc580f1.zip
Indexer: Add logging with env_logger
-rw-r--r--Cargo.lock50
-rw-r--r--indexer/Cargo.toml2
-rw-r--r--indexer/src/main.rs12
3 files changed, 60 insertions, 4 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 6af29e2..c058039 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -364,6 +364,17 @@ dependencies = [
 ]
 
 [[package]]
+name = "atty"
+version = "0.2.14"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
+dependencies = [
+ "hermit-abi",
+ "libc",
+ "winapi 0.3.9",
+]
+
+[[package]]
 name = "autocfg"
 version = "1.1.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -702,6 +713,19 @@ dependencies = [
 ]
 
 [[package]]
+name = "env_logger"
+version = "0.9.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c90bf5f19754d10198ccb95b70664fc925bd1fc090a0fd9a6ebc54acc8cd6272"
+dependencies = [
+ "atty",
+ "humantime",
+ "log",
+ "regex",
+ "termcolor",
+]
+
+[[package]]
 name = "event-listener"
 version = "2.5.3"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1246,6 +1270,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421"
 
 [[package]]
+name = "humantime"
+version = "2.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
+
+[[package]]
 name = "hyper"
 version = "0.13.10"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1308,9 +1338,11 @@ dependencies = [
  "actix-cors",
  "actix-web",
  "actix-web-lab",
+ "env_logger",
  "html2text",
  "kuchiki",
  "lib",
+ "log",
  "scraper",
  "serde",
  "serde_json",
@@ -2552,6 +2584,15 @@ dependencies = [
 ]
 
 [[package]]
+name = "termcolor"
+version = "1.1.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755"
+dependencies = [
+ "winapi-util",
+]
+
+[[package]]
 name = "thin-slice"
 version = "0.1.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2985,6 +3026,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
 
 [[package]]
+name = "winapi-util"
+version = "0.1.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
+dependencies = [
+ "winapi 0.3.9",
+]
+
+[[package]]
 name = "winapi-x86_64-pc-windows-gnu"
 version = "0.4.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/indexer/Cargo.toml b/indexer/Cargo.toml
index 7b64bb3..b94f004 100644
--- a/indexer/Cargo.toml
+++ b/indexer/Cargo.toml
@@ -14,6 +14,8 @@ html2text = "0.4.3"
 serde = { version = "1.0", features = ["derive", "rc"] }
 serde_json = "1.0.87"
 kuchiki = "0.8.1"
+log = "0.4.17"
+env_logger = "0.9.1"
 lib = { path = "../lib" }
 
 [[bin]]
diff --git a/indexer/src/main.rs b/indexer/src/main.rs
index 592a0a6..515062d 100644
--- a/indexer/src/main.rs
+++ b/indexer/src/main.rs
@@ -30,7 +30,9 @@ struct AppState {
 
 #[actix_web::main]
 async fn main() -> std::io::Result<()> {
-    println!("Hello, world! Im the indexer!");
+    env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
+
+    log::info!("Hello, world! Im the indexer!");
 
     serve_http_endpoint("0.0.0.0", 4444).await
 }
@@ -55,6 +57,8 @@ async fn serve_http_endpoint(address: &str, port: u16) -> std::io::Result<()> {
 
 //TODO: Max description size
 //TODO: Current result below search bar updates with it
+//TODO: Remove html symbols italic and stuff in frontend (or apply them?)
+//TODO: Better readme
 
 //TODO: sufficiently simmilar word in search (algorithm)
 #[post("/api/resource")]
@@ -88,7 +92,7 @@ async fn add_resource(
         .filter(|w: &String| !w.is_empty())
         .collect();
 
-    println!("xd: {:?}", fixed_words);
+    log::debug!("xd: {:?}", fixed_words);
 
     let title_selector = scraper::Selector::parse("title").unwrap();
     let meta_selector = scraper::Selector::parse("meta").unwrap();
@@ -141,7 +145,7 @@ async fn add_resource(
     //Now what to do, global lang?, per index lang?, website lang?
     //TODO: max number of results in query
 
-    println!("Added resource: {:?}", indexer.num_of_words());
+    log::debug!("Added resource: {:?}", indexer.num_of_words());
 
     format!("{resource:?}")
 }
@@ -161,7 +165,7 @@ async fn search(
         None => return "[]".to_string(),
     };
 
-    println!("Query: {:?}", query);
+    log::debug!("Query: {:?}", query);
 
     let results = data.indexer.lock().unwrap().search(query);
     //indexer is slow (gets stuck when inserting stuff)