diff --git a/Cargo.lock b/Cargo.lock index 162e0b11fe..ea3121a9de 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1304,7 +1304,6 @@ dependencies = [ "leo-input", "leo-package", "leo-state", - "log", "notify", "num-bigint", "rand", @@ -1335,11 +1334,11 @@ version = "1.0.0" name = "leo-package" version = "1.0.0" dependencies = [ - "log", "serde", "serde_json", "thiserror", "toml", + "tracing", "walkdir", "zip", ] diff --git a/Cargo.toml b/Cargo.toml index 36bdcf03ab..c32c7c28f2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,7 +43,6 @@ dotenv = { version = "0.15.0" } env_logger = { version = "0.7" } from-pest = { version = "0.3.1" } lazy_static = { version = "1.4.0" } -log = { version = "0.4" } notify= { version = "4.0.15" } num-bigint = { version = "0.3" } rand = { version = "0.7" } diff --git a/compiler/Cargo.toml b/compiler/Cargo.toml index 5143814f6a..7d281bb121 100644 --- a/compiler/Cargo.toml +++ b/compiler/Cargo.toml @@ -39,7 +39,6 @@ thiserror = { version = "1.0" } tracing = { version = "0.1" } tracing-subscriber = { version = "0.2" } - [dev-dependencies] num-bigint = { version = "0.3" } diff --git a/leo/commands/add.rs b/leo/commands/add.rs index 25b70e7575..3bd7398160 100644 --- a/leo/commands/add.rs +++ b/leo/commands/add.rs @@ -156,7 +156,7 @@ impl CLI for AddCommand { } } - log::info!("Successfully added a package"); + tracing::info!("Successfully added a package"); Ok(()) } } diff --git a/leo/commands/build.rs b/leo/commands/build.rs index 8874924791..38a1cde19d 100644 --- a/leo/commands/build.rs +++ b/leo/commands/build.rs @@ -86,7 +86,7 @@ impl CLI for BuildCommand { lib_file_path.push(LIB_FILE_NAME); // Log compilation of library file to console - tracing::info!("library file {:?}", lib_file_path); + tracing::info!("library file ({:?})", lib_file_path); // Compile the library file but do not output let _program = Compiler::::parse_program_without_input( @@ -113,7 +113,7 @@ impl CLI for BuildCommand { let state_string = StateFile::new(&package_name).read_from(&path)?; // Log compilation of main file to console - tracing::info!("program file {:?}", main_file_path); + tracing::info!("program file ({:?})", main_file_path); // Load the program at `main_file_path` let program = Compiler::::parse_program_with_input( diff --git a/leo/commands/deploy.rs b/leo/commands/deploy.rs index 1522590ec2..426786e94a 100644 --- a/leo/commands/deploy.rs +++ b/leo/commands/deploy.rs @@ -56,7 +56,7 @@ impl CLI for DeployCommand { // Get the package name let _package_name = Manifest::try_from(&path)?.get_package_name(); - log::info!("Unimplemented - `leo deploy`"); + tracing::info!("Unimplemented - `leo deploy`"); Ok(()) } diff --git a/leo/commands/lint.rs b/leo/commands/lint.rs index f055bdd0cb..a306d5b244 100644 --- a/leo/commands/lint.rs +++ b/leo/commands/lint.rs @@ -56,7 +56,7 @@ impl CLI for LintCommand { // Get the package name let _package_name = Manifest::try_from(&path)?.get_package_name(); - log::info!("Unimplemented - `leo lint`"); + tracing::info!("Unimplemented - `leo lint`"); Ok(()) } diff --git a/leo/commands/login.rs b/leo/commands/login.rs index 415445961a..af5d48dd2d 100644 --- a/leo/commands/login.rs +++ b/leo/commands/login.rs @@ -95,7 +95,7 @@ impl CLI for LoginCommand { Ok(result) => match result.json() { Ok(json) => json, Err(_error) => { - log::error!("Wrong login or password"); + tracing::error!("Wrong login or password"); return Err(WrongLoginOrPassword("Wrong login or password".into()).into()); } }, @@ -124,12 +124,12 @@ impl CLI for LoginCommand { Some(token) => { write_token(token.as_str())?; - log::info!("Login successful."); + tracing::info!("login successful."); Ok(token) } _ => { - log::error!("Failed to login. Please run `leo login -h` for help."); + tracing::error!("Failed to login. Please run `leo login -h` for help."); Err(NoCredentialsProvided.into()) } diff --git a/leo/commands/prove.rs b/leo/commands/prove.rs index eebb39347e..4e859125d7 100644 --- a/leo/commands/prove.rs +++ b/leo/commands/prove.rs @@ -52,7 +52,7 @@ impl CLI for ProveCommand { let path = current_dir()?; let package_name = Manifest::try_from(&path)?.get_package_name(); - log::info!("Proving..."); + tracing::info!("Proving..."); // Start the timer let start = Instant::now(); @@ -61,14 +61,14 @@ impl CLI for ProveCommand { let program_proof = Groth16::>::prove(¶meters, program, rng)?; // Output the proving time - log::info!("Prover completed in {:?} milliseconds", start.elapsed().as_millis()); + tracing::info!("Prover completed in {:?} milliseconds", start.elapsed().as_millis()); // Write the proof file to the output directory let mut proof = vec![]; program_proof.write(&mut proof)?; ProofFile::new(&package_name).write_to(&path, &proof)?; - log::info!("Completed program proving"); + tracing::info!("Completed program proving"); Ok((program_proof, prepared_verifying_key)) } diff --git a/leo/commands/publish.rs b/leo/commands/publish.rs index a268042233..a92537e458 100644 --- a/leo/commands/publish.rs +++ b/leo/commands/publish.rs @@ -96,7 +96,7 @@ impl CLI for PublishCommand { // Create zip file let zip_file = ZipFile::new(&package_name); if zip_file.exists_at(&path) { - log::debug!("Existing package zip file found. Clearing it to regenerate."); + tracing::debug!("Existing package zip file found. Clearing it to regenerate."); // Remove the existing package zip file ZipFile::new(&package_name).remove(&path)?; } @@ -118,8 +118,8 @@ impl CLI for PublishCommand { // If not logged in, then try logging in using JWT. Err(_error) => { - log::warn!("You should be logged in before attempting to publish a package"); - log::info!("Trying to log in using JWT..."); + tracing::warn!("You should be tracingged in before attempting to publish a package"); + tracing::info!("Trying to log in using JWT..."); let options = (None, None, None); LoginCommand::output(options)? @@ -145,17 +145,17 @@ impl CLI for PublishCommand { Ok(json_result) => match json_result.json::() { Ok(json) => json, Err(error) => { - log::warn!("{:?}", error); + tracing::warn!("{:?}", error); return Err(PublishError(PackageNotPublished("Package not published".into()))); } }, Err(error) => { - log::warn!("{:?}", error); + tracing::warn!("{:?}", error); return Err(PublishError(ConnectionUnavalaible("Connection error".into()))); } }; - log::info!("Package published successfully with id: {}", result.package_id); + tracing::info!("Package published successfully with id: {}", result.package_id); Ok(Some(result.package_id)) } } diff --git a/leo/commands/remove.rs b/leo/commands/remove.rs index 7abdbbbaa3..e86e64fcae 100644 --- a/leo/commands/remove.rs +++ b/leo/commands/remove.rs @@ -56,7 +56,7 @@ impl CLI for RemoveCommand { // Get the package name let _package_name = Manifest::try_from(&path)?.get_package_name(); - log::info!("Unimplemented - `leo remove`"); + tracing::info!("Unimplemented - `leo remove`"); Ok(()) } diff --git a/leo/commands/setup.rs b/leo/commands/setup.rs index 634374f7b2..f562c701af 100644 --- a/leo/commands/setup.rs +++ b/leo/commands/setup.rs @@ -73,7 +73,7 @@ impl CLI for SetupCommand { // If keys do not exist or the checksum differs, run the program setup // If keys do not exist or the checksum differs, run the program setup let (proving_key, prepared_verifying_key) = if !keys_exist || checksum_differs { - log::info!("Setup starting..."); + tracing::info!("Setup starting..."); // Start the timer let start = Instant::now(); @@ -84,24 +84,24 @@ impl CLI for SetupCommand { Groth16::, Vec>::setup(program.clone(), rng).unwrap(); // Output the setup time - log::info!("Setup completed in {:?} milliseconds", start.elapsed().as_millis()); + tracing::info!("Setup completed in {:?} milliseconds", start.elapsed().as_millis()); // TODO (howardwu): Convert parameters to a 'proving key' struct for serialization. // Write the proving key file to the output directory let mut proving_key_bytes = vec![]; proving_key.write(&mut proving_key_bytes)?; ProvingKeyFile::new(&package_name).write_to(&path, &proving_key_bytes)?; - log::info!("Saving proving key ({:?})", path); + tracing::info!("Saving proving key ({:?})", path); // Write the verification key file to the output directory let mut verification_key = vec![]; proving_key.vk.write(&mut verification_key)?; VerificationKeyFile::new(&package_name).write_to(&path, &verification_key)?; - log::info!("Saving verification key ({:?})", path); + tracing::info!("Saving verification key ({:?})", path); (proving_key, prepared_verifying_key) } else { - log::info!("Loading saved setup..."); + tracing::info!("Loading saved setup..."); // Read the proving key file from the output directory let proving_key_bytes = ProvingKeyFile::new(&package_name).read_from(&path)?; @@ -117,7 +117,7 @@ impl CLI for SetupCommand { (proving_key, prepared_verifying_key) }; - log::info!("Program setup complete"); + tracing::info!("Program setup complete"); Ok((program, proving_key, prepared_verifying_key)) } diff --git a/leo/commands/test.rs b/leo/commands/test.rs index 1b8e9a5168..13f5f42394 100644 --- a/leo/commands/test.rs +++ b/leo/commands/test.rs @@ -95,7 +95,7 @@ impl CLI for TestCommand { // Run tests let temporary_program = program.clone(); let output = temporary_program.compile_test_constraints(pairs)?; - log::debug!("Compiled constraints - {:#?}", output); + tracing::debug!("Compiled constraints - {:#?}", output); Ok(()) } diff --git a/leo/commands/update.rs b/leo/commands/update.rs index 0abc9cb160..5c3c2f4167 100644 --- a/leo/commands/update.rs +++ b/leo/commands/update.rs @@ -34,9 +34,9 @@ impl UpdateCommand { .build()? .fetch()?; - log::info!("List of available Leo's versions"); + tracing::info!("List of available Leo's versions"); for release in releases { - log::info!("* {}", release.version); + tracing::info!("* {}", release.version); } Ok(()) } @@ -77,22 +77,22 @@ impl CLI for UpdateCommand { (true,) => match UpdateCommand::show_available_releases() { Ok(_) => return Ok(()), Err(e) => { - log::error!("Could not fetch that latest version of Leo"); - log::error!("{}", e); + tracing::error!("Could not fetch that latest version of Leo"); + tracing::error!("{}", e); } }, (false,) => match UpdateCommand::update_to_latest_release() { Ok(status) => { if status.uptodate() { - log::info!("Leo is already on the latest version: {}", status.version()); + tracing::info!("Leo is already on the latest version: {}", status.version()); } else if status.updated() { - log::info!("Leo has successfully updated to version: {}", status.version()); + tracing::info!("Leo has successfully updated to version: {}", status.version()); } return Ok(()); } Err(e) => { - log::error!("Could not update Leo to the latest version"); - log::error!("{}", e); + tracing::error!("Could not update Leo to the latest version"); + tracing::error!("{}", e); } }, } diff --git a/leo/commands/watch.rs b/leo/commands/watch.rs index f4c07e298d..37d1fc2a28 100644 --- a/leo/commands/watch.rs +++ b/leo/commands/watch.rs @@ -47,7 +47,7 @@ impl CLI for WatchCommand { let mut watcher = watcher(tx, Duration::from_secs(INTERVAL)).unwrap(); watcher.watch(LEO_SOURCE_DIR, RecursiveMode::Recursive).unwrap(); - log::info!("Watching Leo source code"); + tracing::info!("Watching Leo source code"); loop { match rx.recv() { // See changes on the write event @@ -55,11 +55,11 @@ impl CLI for WatchCommand { let options = (); match BuildCommand::output(options) { Ok(_output) => { - log::info!("Built successfully"); + tracing::info!("Built successfully"); } Err(e) => { // Syntax error - log::error!("Error {:?}", e); + tracing::error!("Error {:?}", e); } }; } @@ -68,7 +68,7 @@ impl CLI for WatchCommand { // Watch error Err(e) => { - log::error!("watch error: {:?}", e) + tracing::error!("watch error: {:?}", e) // TODO (howardwu): Add graceful termination. } } diff --git a/leo/errors/cli.rs b/leo/errors/cli.rs index e7fe39ab1d..cb7675b38c 100644 --- a/leo/errors/cli.rs +++ b/leo/errors/cli.rs @@ -107,9 +107,21 @@ pub enum CLIError { VerificationKeyFileError(VerificationKeyFileError), } +macro_rules! impl_T { + (for $($t:tt), +) => { + $(impl From<$t> for CLIError { + fn from(error: $t) -> Self { + tracing::error!("{}\n", error); + + CLIError::$t(error) + } + })* + } +} + impl From for CLIError { fn from(error: ZipFileError) -> Self { - log::error!("{}\n", error); + tracing::error!("{}\n", error); CLIError::BytesFileError(error) } } @@ -123,210 +135,210 @@ impl From for CLIError { impl From for CLIError { fn from(error: AddError) -> Self { - log::error!("{}\n", error); + tracing::error!("{}\n", error); CLIError::AddError(error) } } impl From for CLIError { fn from(error: ChecksumFileError) -> Self { - log::error!("{}\n", error); + tracing::error!("{}\n", error); CLIError::ChecksumFileError(error) } } impl From for CLIError { fn from(error: CircuitFileError) -> Self { - log::error!("{}\n", error); + tracing::error!("{}\n", error); CLIError::CircuitFileError(error) } } impl From for CLIError { fn from(error: GitignoreError) -> Self { - log::error!("{}\n", error); + tracing::error!("{}\n", error); CLIError::GitignoreError(error) } } impl From for CLIError { fn from(error: InitError) -> Self { - log::error!("{}\n", error); + tracing::error!("{}\n", error); CLIError::InitError(error) } } impl From for CLIError { fn from(error: ImportsDirectoryError) -> Self { - log::error!("{}\n", error); + tracing::error!("{}\n", error); CLIError::ImportsDirectoryError(error) } } impl From for CLIError { fn from(error: InputsDirectoryError) -> Self { - log::error!("{}\n", error); + tracing::error!("{}\n", error); CLIError::InputDirectoryError(error) } } impl From for CLIError { fn from(error: InputFileError) -> Self { - log::error!("{}\n", error); + tracing::error!("{}\n", error); CLIError::InputFileError(error) } } impl From for CLIError { fn from(error: LibFileError) -> Self { - log::error!("{}\n", error); + tracing::error!("{}\n", error); CLIError::LibFileError(error) } } impl From for CLIError { fn from(error: LoginError) -> Self { - log::error!("{}\n", error); + tracing::error!("{}\n", error); CLIError::LoginError(error) } } impl From for CLIError { fn from(error: MainFileError) -> Self { - log::error!("{}\n", error); + tracing::error!("{}\n", error); CLIError::MainFileError(error) } } impl From for CLIError { fn from(error: ManifestError) -> Self { - log::error!("{}\n", error); + tracing::error!("{}\n", error); CLIError::ManifestError(error) } } impl From for CLIError { fn from(error: NewError) -> Self { - log::error!("{}\n", error); + tracing::error!("{}\n", error); CLIError::NewError(error) } } impl From for CLIError { fn from(error: OutputsDirectoryError) -> Self { - log::error!("{}\n", error); + tracing::error!("{}\n", error); CLIError::OutputDirectoryError(error) } } impl From for CLIError { fn from(error: ProofFileError) -> Self { - log::error!("{}\n", error); + tracing::error!("{}\n", error); CLIError::ProofFileError(error) } } impl From for CLIError { fn from(error: ProvingKeyFileError) -> Self { - log::error!("{}\n", error); + tracing::error!("{}\n", error); CLIError::ProvingKeyFileError(error) } } impl From for CLIError { fn from(error: PublishError) -> Self { - log::error!("{}\n", error); + tracing::error!("{}\n", error); CLIError::PublishError(error) } } impl From for CLIError { fn from(error: READMEError) -> Self { - log::error!("{}\n", error); + tracing::error!("{}\n", error); CLIError::READMEError(error) } } impl From for CLIError { fn from(error: RunError) -> Self { - log::error!("{}\n", error); + tracing::error!("{}\n", error); CLIError::RunError(error) } } impl From for CLIError { fn from(error: SourceDirectoryError) -> Self { - log::error!("{}\n", error); + tracing::error!("{}\n", error); CLIError::SourceDirectoryError(error) } } impl From for CLIError { fn from(error: StateFileError) -> Self { - log::error!("{}\n", error); + tracing::error!("{}\n", error); CLIError::StateFileError(error) } } impl From for CLIError { fn from(error: TestError) -> Self { - log::error!("{}\n", error); + tracing::error!("{}\n", error); CLIError::TestError(error) } } impl From for CLIError { fn from(error: VerificationKeyFileError) -> Self { - log::error!("{}\n", error); + tracing::error!("{}\n", error); CLIError::VerificationKeyFileError(error) } } impl From for CLIError { fn from(error: leo_compiler::errors::CompilerError) -> Self { - log::error!("{}\n", error); + tracing::error!("{}\n", error); CLIError::Crate("leo_compiler", "Program failed due to previous error".into()) } } impl From for CLIError { fn from(error: leo_input::errors::InputParserError) -> Self { - log::error!("{}\n", error); + tracing::error!("{}\n", error); CLIError::Crate("leo_input", "Program failed due to previous error".into()) } } impl From for CLIError { fn from(error: reqwest::Error) -> Self { - log::error!("{}\n", error); + tracing::error!("{}\n", error); CLIError::Crate("rewquest", format!("{}", error)) } } impl From for CLIError { fn from(error: snarkos_errors::algorithms::snark::SNARKError) -> Self { - log::error!("{}\n", error); + tracing::error!("{}\n", error); CLIError::Crate("snarkos_errors", format!("{}", error)) } } impl From for CLIError { fn from(error: snarkos_errors::gadgets::SynthesisError) -> Self { - log::error!("{}\n", error); + tracing::error!("{}\n", error); CLIError::Crate("snarkos_errors", format!("{}", error)) } } impl From for CLIError { fn from(error: serde_json::error::Error) -> Self { - log::error!("{}\n", error); + tracing::error!("{}\n", error); CLIError::Crate("serde_json", format!("{}", error)) } } impl From for CLIError { fn from(error: std::io::Error) -> Self { - log::error!("{}\n", error); + tracing::error!("{}\n", error); CLIError::Crate("std::io", format!("{}", error)) } } diff --git a/leo/logger.rs b/leo/logger.rs index 7615a7406e..ed58e9c16a 100644 --- a/leo/logger.rs +++ b/leo/logger.rs @@ -20,16 +20,16 @@ use tracing_subscriber::FmtSubscriber; const LEVEL_NAME_LENGTH: usize = 10; -#[allow(dead_code)] -fn colored_string(level: log::Level, message: &str) -> colored::ColoredString { - match level { - log::Level::Error => message.bold().red(), - log::Level::Warn => message.bold().yellow(), - log::Level::Info => message.bold().cyan(), - log::Level::Debug => message.bold().magenta(), - log::Level::Trace => message.bold(), - } -} +// #[allow(dead_code)] +// fn colored_string(level: log::Level, message: &str) -> colored::ColoredString { +// match level { +// log::Level::Error => message.bold().red(), +// log::Level::Warn => message.bold().yellow(), +// log::Level::Info => message.bold().cyan(), +// log::Level::Debug => message.bold().magenta(), +// log::Level::Trace => message.bold(), +// } +// } /// Initialize logger with custom format and verbosity. pub fn init_logger(app_name: &'static str, verbosity: usize) { @@ -49,25 +49,25 @@ pub fn init_logger(app_name: &'static str, verbosity: usize) { tracing::subscriber::set_global_default(subscriber).expect("setting default subscriber failed"); - env_logger::builder() - .filter_level(match verbosity { - 0 => log::LevelFilter::Warn, - 1 => log::LevelFilter::Info, - 2 => log::LevelFilter::Debug, - _ => log::LevelFilter::Trace, - }) - .format(move |buf, record| { - let mut padding = String::from("\n"); - for _ in 0..(app_name.len() + LEVEL_NAME_LENGTH + 4) { - padding.push(' '); - } - - writeln!( - buf, - "{:>5} {}", - colored_string(record.level(), app_name), - record.args().to_string().replace("\n", &padding) - ) - }) - .init(); + // env_logger::builder() + // .filter_level(match verbosity { + // 0 => log::LevelFilter::Warn, + // 1 => log::LevelFilter::Info, + // 2 => log::LevelFilter::Debug, + // _ => log::LevelFilter::Trace, + // }) + // .format(move |buf, record| { + // let mut padding = String::from("\n"); + // for _ in 0..(app_name.len() + LEVEL_NAME_LENGTH + 4) { + // padding.push(' '); + // } + // + // writeln!( + // buf, + // "{:>5} {}", + // colored_string(record.level(), app_name), + // record.args().to_string().replace("\n", &padding) + // ) + // }) + // .init(); } diff --git a/leo/main.rs b/leo/main.rs index ed4d4473e4..8537c93bc4 100644 --- a/leo/main.rs +++ b/leo/main.rs @@ -61,7 +61,7 @@ fn main() -> Result<(), CLIError> { if config.auto_update { if let Ok(status) = UpdateCommand::update_to_latest_release() { if status.updated() { - log::info!("Leo has successfully updated to version: {}", status.version()); + tracing::info!("Leo has successfully updated to version: {}", status.version()); } } } diff --git a/package/Cargo.toml b/package/Cargo.toml index fa44c06b8f..ed72034987 100644 --- a/package/Cargo.toml +++ b/package/Cargo.toml @@ -12,10 +12,10 @@ license = "GPL-3.0" edition = "2018" [dependencies] -log = { version = "0.4" } serde = { version = "1.0", features = ["derive"] } serde_json = { version = "1.0" } thiserror = { version = "1.0" } toml = { version = "0.5" } +tracing = { version = "0.1" } walkdir = { version = "2" } zip = { version = "0.5" } diff --git a/package/src/outputs/proof.rs b/package/src/outputs/proof.rs index 4d0a41482f..6f926dc4be 100644 --- a/package/src/outputs/proof.rs +++ b/package/src/outputs/proof.rs @@ -59,7 +59,7 @@ impl ProofFile { let mut file = File::create(&path)?; file.write_all(proof)?; - log::info!("Proof stored ({:?})", path); + tracing::info!("Proof stored ({:?})", path); Ok(()) } diff --git a/package/src/root/zip.rs b/package/src/root/zip.rs index ea89ea747d..055452debf 100644 --- a/package/src/root/zip.rs +++ b/package/src/root/zip.rs @@ -94,14 +94,14 @@ impl ZipFile { // Add file/directory exclusion let included = is_included(name); - log::debug!("Checking if {:?} is included - {}", name, included); + tracing::debug!("Checking if {:?} is included - {}", name, included); if !included { continue; } // Write file or directory if path.is_file() { - log::info!("Adding file {:?} as {:?}", path, name); + tracing::info!("Adding file {:?} as {:?}", path, name); zip.start_file_from_path(name, options)?; let mut f = File::open(path)?; @@ -111,14 +111,14 @@ impl ZipFile { } else if name.as_os_str().len() != 0 { // Only if not root Avoids path spec / warning // and mapname conversion failed error on unzip - log::info!("Adding directory {:?} as {:?}", path, name); + tracing::info!("Adding directory {:?} as {:?}", path, name); zip.add_directory_from_path(name, options)?; } } zip.finish()?; - log::info!("Package zip file created successfully {:?}", path); + tracing::info!("Package zip file created successfully {:?}", path); Ok(()) }