(chore): added better loggin

This commit is contained in:
Jamie Pine 2022-06-21 22:53:07 -07:00
parent dd77aabc47
commit d11b9d0f15
8 changed files with 64 additions and 12 deletions

View file

@ -5,9 +5,12 @@
"consts", "consts",
"countup", "countup",
"creationdate", "creationdate",
"dotenv",
"dotenvy",
"fontsource", "fontsource",
"ipfs", "ipfs",
"Keepsafe", "Keepsafe",
"nodestate",
"pathctx", "pathctx",
"prismjs", "prismjs",
"proptype", "proptype",

42
Cargo.lock generated
View file

@ -1277,6 +1277,15 @@ dependencies = [
"dirs-sys", "dirs-sys",
] ]
[[package]]
name = "dirs"
version = "4.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca3aa72a6f96ea37bbc5aa912f6788242832f75369bdfdadcb0e38423f100059"
dependencies = [
"dirs-sys",
]
[[package]] [[package]]
name = "dirs-next" name = "dirs-next"
version = "2.0.0" version = "2.0.0"
@ -1342,6 +1351,15 @@ dependencies = [
"serde_json", "serde_json",
] ]
[[package]]
name = "dotenvy"
version = "0.15.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7e851a83c30366fd01d75b913588e95e74a1705c1ecc5d58b1f8e1a6d556525f"
dependencies = [
"dirs",
]
[[package]] [[package]]
name = "dtoa" name = "dtoa"
version = "0.4.8" version = "0.4.8"
@ -1487,6 +1505,19 @@ dependencies = [
"syn", "syn",
] ]
[[package]]
name = "env_logger"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b2cf0344971ee6c64c31be0d530793fba457d322dfec2810c453d0ef228f9c3"
dependencies = [
"atty",
"humantime",
"log",
"regex",
"termcolor",
]
[[package]] [[package]]
name = "exr" name = "exr"
version = "1.4.2" version = "1.4.2"
@ -2320,6 +2351,12 @@ version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421"
[[package]]
name = "humantime"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
[[package]] [[package]]
name = "hyper" name = "hyper"
version = "0.14.19" version = "0.14.19"
@ -4817,6 +4854,7 @@ dependencies = [
"chrono", "chrono",
"core-derive", "core-derive",
"data-encoding", "data-encoding",
"env_logger",
"ffmpeg-next", "ffmpeg-next",
"fs_extra", "fs_extra",
"futures", "futures",
@ -5212,6 +5250,8 @@ dependencies = [
name = "spacedrive" name = "spacedrive"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"dotenvy",
"env_logger",
"sdcore", "sdcore",
"swift-rs", "swift-rs",
"tauri", "tauri",
@ -6171,7 +6211,7 @@ version = "1.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675" checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675"
dependencies = [ dependencies = [
"cfg-if 0.1.10", "cfg-if 1.0.0",
"rand 0.8.5", "rand 0.8.5",
"static_assertions", "static_assertions",
] ]

View file

@ -0,0 +1 @@
RUST_LOG=spacedrive=debug,sdcore=debug

View file

@ -21,6 +21,8 @@ sdcore = { path = "../../../core" }
# Universal Dependencies # Universal Dependencies
tokio = { version = "1.17.0", features = ["sync"] } tokio = { version = "1.17.0", features = ["sync"] }
window-shadows = "0.1.2" window-shadows = "0.1.2"
env_logger = "0.9.0"
dotenvy = "0.15.1"
# macOS system libs # macOS system libs
[target.'cfg(target_os = "macos")'.dependencies] [target.'cfg(target_os = "macos")'.dependencies]

View file

@ -1,9 +1,9 @@
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};
use dotenvy::dotenv;
use sdcore::{ClientCommand, ClientQuery, CoreController, CoreEvent, CoreResponse, Node}; use sdcore::{ClientCommand, ClientQuery, CoreController, CoreEvent, CoreResponse, Node};
use tauri::api::path; use tauri::api::path;
use tauri::Manager; use tauri::Manager;
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
mod macos; mod macos;
mod menu; mod menu;
@ -45,6 +45,9 @@ async fn app_ready(app_handle: tauri::AppHandle) {
#[tokio::main] #[tokio::main]
async fn main() { async fn main() {
dotenv().ok();
env_logger::init();
let data_dir = path::data_dir().unwrap_or(std::path::PathBuf::from("./")); let data_dir = path::data_dir().unwrap_or(std::path::PathBuf::from("./"));
// create an instance of the core // create an instance of the core
let (mut node, mut event_receiver) = Node::new(data_dir).await; let (mut node, mut event_receiver) = Node::new(data_dir).await;

View file

@ -34,10 +34,11 @@ thiserror = "1.0.30"
core-derive = { path = "./derive" } core-derive = { path = "./derive" }
tokio = { version = "1.17.0", features = ["sync", "rt"] } tokio = { version = "1.17.0", features = ["sync", "rt"] }
include_dir = {version = "0.7.2", features = ["glob"]} include_dir = { version = "0.7.2", features = ["glob"] }
async-trait = "0.1.52" async-trait = "0.1.52"
image = "0.24.1" image = "0.24.1"
webp = "0.2.2" webp = "0.2.2"
ffmpeg-next = "5.0.3" ffmpeg-next = "5.0.3"
fs_extra = "1.2.0" fs_extra = "1.2.0"
log = "0.4.17" log = { version = "0.4.17", features = ["max_level_trace"] }
env_logger = "0.9.0"

View file

@ -1,6 +1,7 @@
use crate::sys::{create_location, LocationResource}; use crate::sys::{create_location, LocationResource};
use crate::CoreContext; use crate::CoreContext;
use chrono::{DateTime, FixedOffset, Utc}; use chrono::{DateTime, FixedOffset, Utc};
use log::{error, info};
use prisma_client_rust::prisma_models::PrismaValue; use prisma_client_rust::prisma_models::PrismaValue;
use prisma_client_rust::raw; use prisma_client_rust::raw;
use prisma_client_rust::raw::Raw; use prisma_client_rust::raw::Raw;
@ -74,13 +75,13 @@ pub async fn scan_path(
let entry = match entry { let entry = match entry {
Ok(entry) => entry, Ok(entry) => entry,
Err(e) => { Err(e) => {
println!("Error reading file {}", e); error!("Error reading file {}", e);
continue; continue;
} }
}; };
let path = entry.path(); let path = entry.path();
println!("found: {:?}", path); info!("Found filesystem path: {:?}", path);
let parent_path = path let parent_path = path
.parent() .parent()
@ -92,7 +93,7 @@ pub async fn scan_path(
let path_str = match path.as_os_str().to_str() { let path_str = match path.as_os_str().to_str() {
Some(path_str) => path_str, Some(path_str) => path_str,
None => { None => {
println!("Error reading file {}", &path.display()); error!("Error reading file {}", &path.display());
continue; continue;
} }
}; };
@ -144,15 +145,13 @@ pub async fn scan_path(
match prepare_values(&file_path, *file_id, &location, parent_dir_id, *is_dir) { match prepare_values(&file_path, *file_id, &location, parent_dir_id, *is_dir) {
Ok(values) => values.to_vec(), Ok(values) => values.to_vec(),
Err(e) => { Err(e) => {
println!("Error creating file model from path {:?}: {}", file_path, e); error!("Error creating file model from path {:?}: {}", file_path, e);
continue; continue;
} }
}, },
); );
} }
println!("Creating {} file paths. {:?}", files.len(), files);
let raw = Raw::new( let raw = Raw::new(
&format!(" &format!("
INSERT INTO file_paths (id, is_dir, location_id, materialized_path, name, extension, parent_id, date_created) INSERT INTO file_paths (id, is_dir, location_id, materialized_path, name, extension, parent_id, date_created)
@ -165,9 +164,9 @@ pub async fn scan_path(
let count = db._execute_raw(raw).await; let count = db._execute_raw(raw).await;
println!("Inserted {:?} records", count); info!("Inserted {:?} records", count);
} }
println!( info!(
"scan of {:?} completed in {:?}. {:?} files found. db write completed in {:?}", "scan of {:?} completed in {:?}. {:?} files found. db write completed in {:?}",
&path, &path,
scan_read_time, scan_read_time,

View file

@ -8,6 +8,7 @@ use crate::{
CoreContext, CoreContext,
}; };
use int_enum::IntEnum; use int_enum::IntEnum;
use log::info;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::{collections::HashMap, fmt::Debug, sync::Arc}; use std::{collections::HashMap, fmt::Debug, sync::Arc};
use tokio::sync::Mutex; use tokio::sync::Mutex;
@ -38,6 +39,8 @@ impl Jobs {
pub async fn ingest(&mut self, ctx: &CoreContext, job: Box<dyn Job>) { pub async fn ingest(&mut self, ctx: &CoreContext, job: Box<dyn Job>) {
// create worker to process job // create worker to process job
if self.running_workers.len() < MAX_WORKERS { if self.running_workers.len() < MAX_WORKERS {
info!("Running job: {:?}", job.name());
let worker = Worker::new(job); let worker = Worker::new(job);
let id = worker.id(); let id = worker.id();