mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-09-11 13:56:58 +03:00
Update logging with custom formatter
This commit is contained in:
parent
948188ddaf
commit
cc183475ee
36
Cargo.lock
generated
36
Cargo.lock
generated
@ -2357,9 +2357,9 @@ checksum = "fbee7696b84bbf3d89a1c2eccff0850e3047ed46bfcd2e92c29a2d074d57e252"
|
||||
|
||||
[[package]]
|
||||
name = "snarkos-algorithms"
|
||||
version = "1.0.0"
|
||||
version = "1.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "06bef65a6effe9a84009cd96b4bdd53166a736c02a69c738a7a1853283b3902a"
|
||||
checksum = "f587075180fbb776f9b0a7a6ae9af814ea9800173c338ad358dc0418f074b846"
|
||||
dependencies = [
|
||||
"blake2",
|
||||
"derivative",
|
||||
@ -2378,9 +2378,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "snarkos-curves"
|
||||
version = "1.0.0"
|
||||
version = "1.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "581dac15bd0c4ccf63951948e5c6a31a1f7401bc4921f98aa129cf9667baac8a"
|
||||
checksum = "c9a3b914e8c06fda98b0eb66037c548d7bf8458f116b7a3d020ac5c15e8400f3"
|
||||
dependencies = [
|
||||
"derivative",
|
||||
"rand",
|
||||
@ -2405,9 +2405,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "snarkos-dpc"
|
||||
version = "1.0.0"
|
||||
version = "1.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4b2740d419fa4747e6e358052303caf06e3aab7ad758ef5301e5a70320e7460d"
|
||||
checksum = "3d628262e9c79f24826762867e053fa9beab207a2782579db48b38970e1c5d96"
|
||||
dependencies = [
|
||||
"blake2",
|
||||
"derivative",
|
||||
@ -2427,9 +2427,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "snarkos-errors"
|
||||
version = "1.0.0"
|
||||
version = "1.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "45fbdc0916755cdf9522f6abc20103681f0d23308067b1a53be91fe216392d37"
|
||||
checksum = "03b9d85575ed5ef6fa64821a53acbff55dd935e5d9447c7a3233ed689f0170f6"
|
||||
dependencies = [
|
||||
"base58",
|
||||
"bech32",
|
||||
@ -2444,9 +2444,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "snarkos-gadgets"
|
||||
version = "1.0.0"
|
||||
version = "1.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0fdc93bdddb0917013f4c7586b1207e90c714ddfdcf1265a69e0a82d5c7bc608"
|
||||
checksum = "c7ee25ebd815b406118ec5f81a280818bd7f40c05e288064774b1939fdc8d0e9"
|
||||
dependencies = [
|
||||
"derivative",
|
||||
"digest 0.8.1",
|
||||
@ -2460,9 +2460,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "snarkos-models"
|
||||
version = "1.0.0"
|
||||
version = "1.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9e147408d94ad28fdf0de74c1225b2ec67860b9bddb2567013d93ccb299b333e"
|
||||
checksum = "fd7f31748377c4a7b9abc3cb932478b87ee7d2fedb5298ff5c8de2991784d056"
|
||||
dependencies = [
|
||||
"bincode",
|
||||
"derivative",
|
||||
@ -2477,9 +2477,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "snarkos-objects"
|
||||
version = "1.0.0"
|
||||
version = "1.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "62930e0e8ce3004c871ae640844e322d68cf9ad0ad73bf80f9082e1c0cd1ee71"
|
||||
checksum = "a39eb0cfc10f667bd47f137cbf52eb4ba695e8c430c324eed1033f4b346fbe23"
|
||||
dependencies = [
|
||||
"base58",
|
||||
"bech32",
|
||||
@ -2519,9 +2519,9 @@ checksum = "7cf0f5fd8121285811d5b5f7c61e85e176c2ca55d8009e24e151308a7eaa0db6"
|
||||
|
||||
[[package]]
|
||||
name = "snarkos-storage"
|
||||
version = "1.0.0"
|
||||
version = "1.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6763f78edd89f0694feeaaa51a16ad663ee7bdec17f88bc239ab121507f794f4"
|
||||
checksum = "1b2e135ee32d10fb561f6071770a6f2db31f1a01d0a07af3e62c467aee5a5d16"
|
||||
dependencies = [
|
||||
"bincode",
|
||||
"hex",
|
||||
@ -2539,9 +2539,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "snarkos-utilities"
|
||||
version = "1.0.0"
|
||||
version = "1.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "21ad2b96414c45c2f90e9344b1420c9db2fbbb9435d6f1da3e2f819da1b08c05"
|
||||
checksum = "8a20c792056bd64407305a53f406a96b6f032edcf8dc96c24262ed91d4603361"
|
||||
dependencies = [
|
||||
"bincode",
|
||||
"rand",
|
||||
|
14
Cargo.toml
14
Cargo.toml
@ -28,12 +28,12 @@ leo-input = { path = "./input", version = "1.0.0" }
|
||||
leo-package = { path = "./package", version = "1.0.0" }
|
||||
leo-state = { path = "./state", version = "1.0.0" }
|
||||
|
||||
snarkos-algorithms = { version = "1.0.0", default-features = false }
|
||||
snarkos-curves = { version = "1.0.0", default-features = false }
|
||||
snarkos-errors = { version = "1.0.0", default-features = false }
|
||||
snarkos-gadgets = { version = "1.0.0", default-features = false }
|
||||
snarkos-models = { version = "1.0.0", default-features = false }
|
||||
snarkos-utilities = { version = "1.0.0" }
|
||||
snarkos-algorithms = { version = "1.1.3", default-features = false }
|
||||
snarkos-curves = { version = "1.1.3", default-features = false }
|
||||
snarkos-errors = { version = "1.1.3", default-features = false }
|
||||
snarkos-gadgets = { version = "1.1.3", default-features = false }
|
||||
snarkos-models = { version = "1.1.3", default-features = false }
|
||||
snarkos-utilities = { version = "1.1.3" }
|
||||
|
||||
clap = { version = "2.33.3" }
|
||||
colored = { version = "2.0" }
|
||||
@ -54,7 +54,7 @@ serde_json = { version = "1.0" }
|
||||
thiserror = { version = "1.0" }
|
||||
toml = { version = "0.5" }
|
||||
tracing = { version = "0.1" }
|
||||
tracing-subscriber = { version = "0.2" }
|
||||
tracing-subscriber = { version = "0.2", features = ["fmt"] }
|
||||
zip = { version = "0.5" }
|
||||
|
||||
[dev-dependencies]
|
||||
|
@ -19,13 +19,13 @@ leo-package = { path = "../package", version = "1.0.0"}
|
||||
leo-typed = { path = "../typed", version = "1.0.0" }
|
||||
leo-state = { path = "../state", version = "1.0.0" }
|
||||
|
||||
snarkos-curves = { version = "1.0.0", default-features = false }
|
||||
snarkos-dpc = { version = "1.0.0", default-features = false }
|
||||
snarkos-errors = { version = "1.0.0", default-features = false }
|
||||
snarkos-gadgets = { version = "1.0.0", default-features = false }
|
||||
snarkos-models = { version = "1.0.0", default-features = false }
|
||||
snarkos-objects = { version = "1.0.0", default-features = false }
|
||||
snarkos-utilities = { version = "1.0.0" }
|
||||
snarkos-curves = { version = "1.1.3", default-features = false }
|
||||
snarkos-dpc = { version = "1.1.3", default-features = false }
|
||||
snarkos-errors = { version = "1.1.3", default-features = false }
|
||||
snarkos-gadgets = { version = "1.1.3", default-features = false }
|
||||
snarkos-models = { version = "1.1.3", default-features = false }
|
||||
snarkos-objects = { version = "1.1.3", default-features = false }
|
||||
snarkos-utilities = { version = "1.1.3" }
|
||||
|
||||
bincode = { version = "1.0" }
|
||||
hex = { version = "0.4.2" }
|
||||
|
@ -12,13 +12,13 @@ license = "GPL-3.0"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
snarkos-errors = { version = "1.0.0", default-features = false }
|
||||
snarkos-models = { version = "1.0.0", default-features = false }
|
||||
snarkos-utilities = { version = "1.0.0" }
|
||||
snarkos-errors = { version = "1.1.3", default-features = false }
|
||||
snarkos-models = { version = "1.1.3", default-features = false }
|
||||
snarkos-utilities = { version = "1.1.3" }
|
||||
|
||||
rand = { version = "0.7", default-features = false }
|
||||
rand_xorshift = { version = "0.2", default-features = false }
|
||||
thiserror = { version = "1.0" }
|
||||
|
||||
[dev-dependencies]
|
||||
snarkos-utilities = { version = "1.0.0" }
|
||||
snarkos-utilities = { version = "1.1.3" }
|
@ -12,11 +12,11 @@ license = "GPL-3.0"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
snarkos-algorithms = { version = "1.0.0", default-features = false }
|
||||
snarkos-curves = { version = "1.0.0", default-features = false }
|
||||
snarkos-errors = { version = "1.0.0", default-features = false }
|
||||
snarkos-gadgets = { version = "1.0.0", default-features = false }
|
||||
snarkos-models = { version = "1.0.0", default-features = false }
|
||||
snarkos-algorithms = { version = "1.1.3", default-features = false }
|
||||
snarkos-curves = { version = "1.1.3", default-features = false }
|
||||
snarkos-errors = { version = "1.1.3", default-features = false }
|
||||
snarkos-gadgets = { version = "1.1.3", default-features = false }
|
||||
snarkos-models = { version = "1.1.3", default-features = false }
|
||||
|
||||
from-pest = { version = "0.3.1" }
|
||||
pest = { version = "2.0" }
|
||||
|
@ -56,7 +56,7 @@ impl CLI for BuildCommand {
|
||||
#[cfg_attr(tarpaulin, skip)]
|
||||
fn output(_options: Self::Options) -> Result<Self::Output, CLIError> {
|
||||
// Begin "Compiling" context for console logging
|
||||
let span = tracing::span!(tracing::Level::INFO, "Compiling");
|
||||
let span = tracing::span!(tracing::Level::INFO, "Compiler");
|
||||
let enter = span.enter();
|
||||
|
||||
let path = current_dir()?;
|
||||
@ -75,6 +75,8 @@ impl CLI for BuildCommand {
|
||||
let mut output_directory = package_path.clone();
|
||||
output_directory.push(OUTPUTS_DIRECTORY_NAME);
|
||||
|
||||
tracing::info!("Starting...");
|
||||
|
||||
// Start the timer
|
||||
let start = Instant::now();
|
||||
|
||||
@ -86,7 +88,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!("Compiling library... ({:?})", lib_file_path);
|
||||
|
||||
// Compile the library file but do not output
|
||||
let _program = Compiler::<Fq, EdwardsGroupType>::parse_program_without_input(
|
||||
@ -94,6 +96,7 @@ impl CLI for BuildCommand {
|
||||
lib_file_path.clone(),
|
||||
output_directory.clone(),
|
||||
)?;
|
||||
tracing::info!("Complete");
|
||||
};
|
||||
|
||||
// Compile the main.leo file along with constraints
|
||||
@ -113,7 +116,7 @@ impl CLI for BuildCommand {
|
||||
let state_string = StateFile::new(&package_name).read_from(&path)?;
|
||||
|
||||
// Log compilation of files to console
|
||||
tracing::info!("Program file ({:?})", main_file_path);
|
||||
tracing::info!("Compiling main program... ({:?})", main_file_path);
|
||||
|
||||
// Load the program at `main_file_path`
|
||||
let program = Compiler::<Fq, EdwardsGroupType>::parse_program_with_input(
|
||||
@ -178,12 +181,14 @@ impl CLI for BuildCommand {
|
||||
tracing::debug!("Checksum saved ({:?})", path);
|
||||
}
|
||||
|
||||
tracing::info!("Complete");
|
||||
|
||||
// Drop "Compiling" context for console logging
|
||||
drop(enter);
|
||||
|
||||
// Begin "Finished" context for console logging todo: @collin figure a way to get this output with tracing without dropping span
|
||||
tracing::span!(tracing::Level::INFO, "Finished").in_scope(|| {
|
||||
tracing::info!("Program compiled in {} milliseconds\n", start.elapsed().as_millis());
|
||||
tracing::info!("Completed in {} milliseconds\n", start.elapsed().as_millis());
|
||||
});
|
||||
|
||||
return Ok(Some((program, checksum_differs)));
|
||||
|
@ -51,7 +51,7 @@ impl CLI for DeployCommand {
|
||||
fn output(options: Self::Options) -> Result<Self::Output, CLIError> {
|
||||
// Begin "Deploy" context for console logging
|
||||
let span = tracing::span!(tracing::Level::INFO, "Deploying");
|
||||
let enter = span.enter();
|
||||
let _enter = span.enter();
|
||||
|
||||
let path = current_dir()?;
|
||||
|
||||
|
@ -48,8 +48,8 @@ impl CLI for ProveCommand {
|
||||
fn output(options: Self::Options) -> Result<Self::Output, CLIError> {
|
||||
let (program, parameters, prepared_verifying_key) = SetupCommand::output(options)?;
|
||||
|
||||
// Begin "Proving" context for console logging
|
||||
let span = tracing::span!(tracing::Level::INFO, "Proving");
|
||||
// Begin "Prover" context for console logging
|
||||
let span = tracing::span!(tracing::Level::INFO, "Prover");
|
||||
let enter = span.enter();
|
||||
|
||||
// Get the package name
|
||||
@ -64,20 +64,20 @@ impl CLI for ProveCommand {
|
||||
let rng = &mut thread_rng();
|
||||
let program_proof = Groth16::<Bls12_377, _, Vec<Fr>>::prove(¶meters, program, rng)?;
|
||||
|
||||
// Output the proving time
|
||||
tracing::info!("Prover completed in {:?} milliseconds", start.elapsed().as_millis());
|
||||
// Finish the timer
|
||||
let end = 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)?;
|
||||
|
||||
// Drop "Proving" context for console logging
|
||||
// Drop "Prover" context for console logging
|
||||
drop(enter);
|
||||
|
||||
// Begin "Finished" context for console logging
|
||||
tracing::span!(tracing::Level::INFO, "Finished").in_scope(|| {
|
||||
tracing::info!("Program proving complete\n");
|
||||
tracing::info!("Completed in {:?} milliseconds\n", end);
|
||||
});
|
||||
|
||||
Ok((program_proof, prepared_verifying_key))
|
||||
|
@ -22,7 +22,7 @@ use snarkos_curves::bls12_377::{Bls12_377, Fr};
|
||||
use snarkos_models::algorithms::SNARK;
|
||||
|
||||
use clap::ArgMatches;
|
||||
use std::time::{Duration, Instant};
|
||||
use std::time::Instant;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct RunCommand;
|
||||
@ -48,15 +48,15 @@ impl CLI for RunCommand {
|
||||
let (proof, prepared_verifying_key) = ProveCommand::output(options)?;
|
||||
|
||||
// Begin "Verifying" context for console logging
|
||||
let span = tracing::span!(tracing::Level::INFO, "Verifying");
|
||||
let span = tracing::span!(tracing::Level::INFO, "Verifier");
|
||||
let enter = span.enter();
|
||||
|
||||
tracing::info!("Starting...");
|
||||
|
||||
let mut verifying = Duration::new(0, 0);
|
||||
|
||||
// Start the timer
|
||||
let start = Instant::now();
|
||||
|
||||
// Run the verifier
|
||||
let is_success = Groth16::<Bls12_377, Compiler<Fr, EdwardsGroupType>, Vec<Fr>>::verify(
|
||||
&prepared_verifying_key,
|
||||
&vec![],
|
||||
@ -64,16 +64,21 @@ impl CLI for RunCommand {
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
verifying += start.elapsed();
|
||||
// End the timer
|
||||
let end = start.elapsed().as_millis();
|
||||
|
||||
tracing::info!("Verifier completed in {:?} milliseconds", verifying.as_millis());
|
||||
// Log the verifier output
|
||||
match is_success {
|
||||
true => tracing::info!("Proof is valid"),
|
||||
false => tracing::error!("Proof is invalid"),
|
||||
};
|
||||
|
||||
// Drop "Verifying" context for console logging
|
||||
drop(enter);
|
||||
|
||||
// Begin "Finished" context for console logging
|
||||
tracing::span!(tracing::Level::INFO, "Finished").in_scope(|| {
|
||||
tracing::info!("Verifier output : \"{}\"\n", is_success);
|
||||
tracing::info!("Completed in {:?} milliseconds\n", end);
|
||||
});
|
||||
|
||||
Ok(())
|
||||
|
@ -76,7 +76,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 {
|
||||
let (end, proving_key, prepared_verifying_key) = if !keys_exist || checksum_differs {
|
||||
tracing::info!("Starting...");
|
||||
|
||||
// Start the timer for setup
|
||||
@ -87,38 +87,52 @@ impl CLI for SetupCommand {
|
||||
let (proving_key, prepared_verifying_key) =
|
||||
Groth16::<Bls12_377, Compiler<Fr, _>, Vec<Fr>>::setup(program.clone(), rng).unwrap();
|
||||
|
||||
// Output the setup time
|
||||
tracing::info!("Completed in {:?} milliseconds", setup_start.elapsed().as_millis());
|
||||
// End the timer
|
||||
let end = setup_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 proving_key_file = ProvingKeyFile::new(&package_name);
|
||||
tracing::info!("Saving proving key ({:?})", proving_key_file.full_path(&path));
|
||||
let mut proving_key_bytes = vec![];
|
||||
proving_key.write(&mut proving_key_bytes)?;
|
||||
let lpk_file = ProvingKeyFile::new(&package_name).write_to(&path, &proving_key_bytes)?;
|
||||
tracing::info!("Saving proving key ({:?})", lpk_file);
|
||||
let _ = proving_key_file.write_to(&path, &proving_key_bytes)?;
|
||||
tracing::info!("Complete");
|
||||
|
||||
// Write the verification key file to the output directory
|
||||
let verification_key_file = VerificationKeyFile::new(&package_name);
|
||||
tracing::info!("Saving verification key ({:?})", verification_key_file.full_path(&path));
|
||||
let mut verification_key = vec![];
|
||||
proving_key.vk.write(&mut verification_key)?;
|
||||
let lvk_file = VerificationKeyFile::new(&package_name).write_to(&path, &verification_key)?;
|
||||
tracing::info!("Saving verification key ({:?})", lvk_file);
|
||||
let _ = verification_key_file.write_to(&path, &verification_key)?;
|
||||
tracing::info!("Complete");
|
||||
|
||||
(proving_key, prepared_verifying_key)
|
||||
(end, proving_key, prepared_verifying_key)
|
||||
} else {
|
||||
tracing::info!("Loading saved setup...");
|
||||
tracing::info!("Detected saved setup");
|
||||
|
||||
// Start the timer for setup
|
||||
let setup_start = Instant::now();
|
||||
|
||||
// Read the proving key file from the output directory
|
||||
tracing::info!("Loading proving key...");
|
||||
let proving_key_bytes = ProvingKeyFile::new(&package_name).read_from(&path)?;
|
||||
let proving_key = Parameters::<Bls12_377>::read(proving_key_bytes.as_slice(), true)?;
|
||||
tracing::info!("Complete");
|
||||
|
||||
// Read the verification key file from the output directory
|
||||
tracing::info!("Loading verification key...");
|
||||
let verifying_key_bytes = VerificationKeyFile::new(&package_name).read_from(&path)?;
|
||||
let verifying_key = VerifyingKey::<Bls12_377>::read(verifying_key_bytes.as_slice())?;
|
||||
|
||||
// Derive the prepared verifying key file from the verifying key
|
||||
let prepared_verifying_key = PreparedVerifyingKey::<Bls12_377>::from(verifying_key);
|
||||
tracing::info!("Complete");
|
||||
|
||||
(proving_key, prepared_verifying_key)
|
||||
// End the timer
|
||||
let end = setup_start.elapsed().as_millis();
|
||||
|
||||
(end, proving_key, prepared_verifying_key)
|
||||
};
|
||||
|
||||
// Drop "Setup" context for console logging
|
||||
@ -126,7 +140,7 @@ impl CLI for SetupCommand {
|
||||
|
||||
// Begin "Finished" context for console logging
|
||||
tracing::span!(tracing::Level::INFO, "Finished").in_scope(|| {
|
||||
tracing::info!("Program setup complete\n");
|
||||
tracing::info!("Completed in {:?} milliseconds\n", end);
|
||||
});
|
||||
|
||||
Ok((program, proving_key, prepared_verifying_key))
|
||||
|
215
leo/logger.rs
215
leo/logger.rs
@ -15,24 +15,187 @@
|
||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use colored::Colorize;
|
||||
use std::io::Write;
|
||||
use tracing_subscriber::FmtSubscriber;
|
||||
use std::fmt;
|
||||
use tracing::{event::Event, subscriber::Subscriber};
|
||||
use tracing_subscriber::{
|
||||
fmt::{format::*, time::*, FmtContext, FormattedFields},
|
||||
registry::LookupSpan,
|
||||
FmtSubscriber,
|
||||
};
|
||||
|
||||
const LEVEL_NAME_LENGTH: usize = 10;
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Format<F = Full, T = SystemTime> {
|
||||
format: F,
|
||||
pub(crate) timer: T,
|
||||
pub(crate) ansi: bool,
|
||||
pub(crate) display_target: bool,
|
||||
pub(crate) display_level: bool,
|
||||
pub(crate) display_thread_id: bool,
|
||||
pub(crate) display_thread_name: bool,
|
||||
}
|
||||
|
||||
// #[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(),
|
||||
// }
|
||||
// }
|
||||
impl<F, T> Format<F, T> {
|
||||
/// Use the full JSON format.
|
||||
///
|
||||
/// The full format includes fields from all entered spans.
|
||||
///
|
||||
/// # Example Output
|
||||
///
|
||||
/// ```ignore,json
|
||||
/// {"timestamp":"Feb 20 11:28:15.096","level":"INFO","target":"mycrate","fields":{"message":"some message", "key": "value"}}
|
||||
/// ```
|
||||
///
|
||||
/// # Options
|
||||
///
|
||||
/// - [`Format::flatten_event`] can be used to enable flattening event fields into the root
|
||||
/// object.
|
||||
///
|
||||
/// [`Format::flatten_event`]: #method.flatten_event
|
||||
#[cfg(feature = "json")]
|
||||
pub fn json(self) -> Format<Json, T> {
|
||||
Format {
|
||||
format: Json::default(),
|
||||
timer: self.timer,
|
||||
ansi: self.ansi,
|
||||
display_target: self.display_target,
|
||||
display_level: self.display_level,
|
||||
display_thread_id: self.display_thread_id,
|
||||
display_thread_name: self.display_thread_name,
|
||||
}
|
||||
}
|
||||
|
||||
/// Use the given [`timer`] for log message timestamps.
|
||||
///
|
||||
/// See [`time`] for the provided timer implementations.
|
||||
///
|
||||
/// Note that using the `chrono` feature flag enables the
|
||||
/// additional time formatters [`ChronoUtc`] and [`ChronoLocal`].
|
||||
///
|
||||
/// [`time`]: ./time/index.html
|
||||
/// [`timer`]: ./time/trait.FormatTime.html
|
||||
/// [`ChronoUtc`]: ./time/struct.ChronoUtc.html
|
||||
/// [`ChronoLocal`]: ./time/struct.ChronoLocal.html
|
||||
pub fn with_timer<T2>(self, timer: T2) -> Format<F, T2> {
|
||||
Format {
|
||||
format: self.format,
|
||||
timer,
|
||||
ansi: self.ansi,
|
||||
display_target: self.display_target,
|
||||
display_level: self.display_level,
|
||||
display_thread_id: self.display_thread_id,
|
||||
display_thread_name: self.display_thread_name,
|
||||
}
|
||||
}
|
||||
|
||||
/// Do not emit timestamps with log messages.
|
||||
pub fn without_time(self) -> Format<F, ()> {
|
||||
Format {
|
||||
format: self.format,
|
||||
timer: (),
|
||||
ansi: self.ansi,
|
||||
display_target: self.display_target,
|
||||
display_level: self.display_level,
|
||||
display_thread_id: self.display_thread_id,
|
||||
display_thread_name: self.display_thread_name,
|
||||
}
|
||||
}
|
||||
|
||||
/// Enable ANSI terminal colors for formatted output.
|
||||
pub fn with_ansi(self, ansi: bool) -> Format<F, T> {
|
||||
Format { ansi, ..self }
|
||||
}
|
||||
|
||||
/// Sets whether or not an event's target is displayed.
|
||||
pub fn with_target(self, display_target: bool) -> Format<F, T> {
|
||||
Format { display_target, ..self }
|
||||
}
|
||||
|
||||
/// Sets whether or not an event's level is displayed.
|
||||
pub fn with_level(self, display_level: bool) -> Format<F, T> {
|
||||
Format { display_level, ..self }
|
||||
}
|
||||
|
||||
/// Sets whether or not the [thread ID] of the current thread is displayed
|
||||
/// when formatting events
|
||||
///
|
||||
/// [thread ID]: https://doc.rust-lang.org/stable/std/thread/struct.ThreadId.html
|
||||
pub fn with_thread_ids(self, display_thread_id: bool) -> Format<F, T> {
|
||||
Format {
|
||||
display_thread_id,
|
||||
..self
|
||||
}
|
||||
}
|
||||
|
||||
/// Sets whether or not the [name] of the current thread is displayed
|
||||
/// when formatting events
|
||||
///
|
||||
/// [name]: https://doc.rust-lang.org/stable/std/thread/index.html#naming-threads
|
||||
pub fn with_thread_names(self, display_thread_name: bool) -> Format<F, T> {
|
||||
Format {
|
||||
display_thread_name,
|
||||
..self
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Format<Full, SystemTime> {
|
||||
fn default() -> Self {
|
||||
Format {
|
||||
format: Full,
|
||||
timer: SystemTime,
|
||||
ansi: true,
|
||||
display_target: true,
|
||||
display_level: true,
|
||||
display_thread_id: false,
|
||||
display_thread_name: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
impl<S, N, T> FormatEvent<S, N> for Format<Full, T>
|
||||
where
|
||||
S: Subscriber + for<'a> LookupSpan<'a>,
|
||||
N: for<'a> FormatFields<'a> + 'static,
|
||||
T: FormatTime,
|
||||
{
|
||||
fn format_event(&self, ctx: &FmtContext<'_, S, N>, writer: &mut dyn fmt::Write, event: &Event<'_>) -> fmt::Result {
|
||||
let meta = event.metadata();
|
||||
|
||||
if self.display_level {
|
||||
fn colored_string(level: &tracing::Level, message: &str) -> colored::ColoredString {
|
||||
match *level {
|
||||
tracing::Level::ERROR => message.bold().red(),
|
||||
tracing::Level::WARN => message.bold().yellow(),
|
||||
tracing::Level::INFO => message.bold().cyan(),
|
||||
tracing::Level::DEBUG => message.bold().magenta(),
|
||||
tracing::Level::TRACE => message.bold(),
|
||||
}
|
||||
}
|
||||
|
||||
let mut message = "".to_string();
|
||||
|
||||
let scope = ctx.scope();
|
||||
for span in scope {
|
||||
message += span.metadata().name();
|
||||
|
||||
let ext = span.extensions();
|
||||
let fields = &ext
|
||||
.get::<FormattedFields<N>>()
|
||||
.expect("Unable to find FormattedFields in extensions; this is a bug");
|
||||
if !fields.is_empty() {
|
||||
message += &format!("{{{}}}", fields);
|
||||
}
|
||||
}
|
||||
|
||||
write!(writer, "{:>12} ", colored_string(meta.level(), &message)).expect("Error writing event");
|
||||
}
|
||||
|
||||
ctx.format_fields(writer, event)?;
|
||||
writeln!(writer)
|
||||
}
|
||||
}
|
||||
|
||||
/// Initialize logger with custom format and verbosity.
|
||||
pub fn init_logger(app_name: &'static str, verbosity: usize) {
|
||||
pub fn init_logger(_app_name: &'static str, verbosity: usize) {
|
||||
let subscriber = FmtSubscriber::builder()
|
||||
// all spans/events with a level higher than TRACE (e.g, debug, info, warn, etc.)
|
||||
// will be written to stdout.
|
||||
@ -44,30 +207,8 @@ pub fn init_logger(app_name: &'static str, verbosity: usize) {
|
||||
})
|
||||
.without_time()
|
||||
.with_target(false)
|
||||
// completes the builder.
|
||||
.event_format(Format::default())
|
||||
.finish();
|
||||
|
||||
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();
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ impl ProofFile {
|
||||
let mut file = File::create(&path)?;
|
||||
file.write_all(proof)?;
|
||||
|
||||
tracing::info!("Saving proof ({:?})", path);
|
||||
tracing::info!("Saving proof... ({:?})", path);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -39,6 +39,10 @@ impl ProvingKeyFile {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn full_path(&self, path: &PathBuf) -> PathBuf {
|
||||
self.setup_file_path(path)
|
||||
}
|
||||
|
||||
pub fn exists_at(&self, path: &PathBuf) -> bool {
|
||||
let path = self.setup_file_path(path);
|
||||
path.exists()
|
||||
|
@ -39,6 +39,10 @@ impl VerificationKeyFile {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn full_path(&self, path: &PathBuf) -> PathBuf {
|
||||
self.setup_file_path(path)
|
||||
}
|
||||
|
||||
pub fn exists_at(&self, path: &PathBuf) -> bool {
|
||||
let path = self.setup_file_path(path);
|
||||
path.exists()
|
||||
|
@ -15,17 +15,17 @@ edition = "2018"
|
||||
leo-input = { path = "../input", version = "1.0.0" }
|
||||
leo-typed = { path = "../typed", version = "1.0.0" }
|
||||
|
||||
snarkos-algorithms = { version = "1.0.0", default-features = false }
|
||||
snarkos-curves = { version = "1.0.0", default-features = false }
|
||||
snarkos-dpc = { version = "1.0.0", default-features = false }
|
||||
snarkos-errors = { version = "1.0.0", default-features = false }
|
||||
snarkos-models = { version = "1.0.0", default-features = false }
|
||||
snarkos-objects = { version = "1.0.0", default-features = false }
|
||||
snarkos-utilities = { version = "1.0.0" }
|
||||
snarkos-algorithms = { version = "1.1.3", default-features = false }
|
||||
snarkos-curves = { version = "1.1.3", default-features = false }
|
||||
snarkos-dpc = { version = "1.1.3", default-features = false }
|
||||
snarkos-errors = { version = "1.1.3", default-features = false }
|
||||
snarkos-models = { version = "1.1.3", default-features = false }
|
||||
snarkos-objects = { version = "1.1.3", default-features = false }
|
||||
snarkos-utilities = { version = "1.1.3" }
|
||||
|
||||
rand = { version = "0.7" }
|
||||
rand_xorshift = { version = "0.2" }
|
||||
thiserror = { version = "1.0" }
|
||||
|
||||
[dev-dependencies]
|
||||
snarkos-storage = { version = "1.0.0" }
|
||||
snarkos-storage = { version = "1.1.3" }
|
||||
|
@ -24,8 +24,8 @@ harness = false
|
||||
leo-ast = { path = "../ast", version = "1.0.0" }
|
||||
leo-input = { path = "../input", version = "1.0.0" }
|
||||
|
||||
snarkos-errors = { version = "1.0.0", default-features = false }
|
||||
snarkos-models = { version = "1.0.0", default-features = false }
|
||||
snarkos-errors = { version = "1.1.3", default-features = false }
|
||||
snarkos-models = { version = "1.1.3", default-features = false }
|
||||
|
||||
pest = { version = "2.0" }
|
||||
serde = { version = "1.0" }
|
||||
|
Loading…
Reference in New Issue
Block a user