mirror of
https://github.com/AleoHQ/leo.git
synced 2024-11-13 08:47:17 +03:00
use tracing in package and leo cli
This commit is contained in:
parent
da843e452e
commit
3f1b1e857c
3
Cargo.lock
generated
3
Cargo.lock
generated
@ -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",
|
||||
]
|
||||
|
@ -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" }
|
||||
|
@ -39,7 +39,6 @@ thiserror = { version = "1.0" }
|
||||
tracing = { version = "0.1" }
|
||||
tracing-subscriber = { version = "0.2" }
|
||||
|
||||
|
||||
[dev-dependencies]
|
||||
num-bigint = { version = "0.3" }
|
||||
|
||||
|
@ -156,7 +156,7 @@ impl CLI for AddCommand {
|
||||
}
|
||||
}
|
||||
|
||||
log::info!("Successfully added a package");
|
||||
tracing::info!("Successfully added a package");
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
@ -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::<Fq, EdwardsGroupType>::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::<Fq, EdwardsGroupType>::parse_program_with_input(
|
||||
|
@ -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(())
|
||||
}
|
||||
|
@ -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(())
|
||||
}
|
||||
|
@ -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())
|
||||
}
|
||||
|
@ -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::<Bls12_377, _, Vec<Fr>>::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))
|
||||
}
|
||||
|
@ -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::<ResponseJson>() {
|
||||
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))
|
||||
}
|
||||
}
|
||||
|
@ -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(())
|
||||
}
|
||||
|
@ -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::<Bls12_377, Compiler<Fr, _>, Vec<Fr>>::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))
|
||||
}
|
||||
|
@ -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(())
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
},
|
||||
}
|
||||
|
@ -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.
|
||||
}
|
||||
}
|
||||
|
@ -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<ZipFileError> for CLIError {
|
||||
fn from(error: ZipFileError) -> Self {
|
||||
log::error!("{}\n", error);
|
||||
tracing::error!("{}\n", error);
|
||||
CLIError::BytesFileError(error)
|
||||
}
|
||||
}
|
||||
@ -123,210 +135,210 @@ impl From<BuildError> for CLIError {
|
||||
|
||||
impl From<AddError> for CLIError {
|
||||
fn from(error: AddError) -> Self {
|
||||
log::error!("{}\n", error);
|
||||
tracing::error!("{}\n", error);
|
||||
CLIError::AddError(error)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ChecksumFileError> for CLIError {
|
||||
fn from(error: ChecksumFileError) -> Self {
|
||||
log::error!("{}\n", error);
|
||||
tracing::error!("{}\n", error);
|
||||
CLIError::ChecksumFileError(error)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<CircuitFileError> for CLIError {
|
||||
fn from(error: CircuitFileError) -> Self {
|
||||
log::error!("{}\n", error);
|
||||
tracing::error!("{}\n", error);
|
||||
CLIError::CircuitFileError(error)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<GitignoreError> for CLIError {
|
||||
fn from(error: GitignoreError) -> Self {
|
||||
log::error!("{}\n", error);
|
||||
tracing::error!("{}\n", error);
|
||||
CLIError::GitignoreError(error)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<InitError> for CLIError {
|
||||
fn from(error: InitError) -> Self {
|
||||
log::error!("{}\n", error);
|
||||
tracing::error!("{}\n", error);
|
||||
CLIError::InitError(error)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ImportsDirectoryError> for CLIError {
|
||||
fn from(error: ImportsDirectoryError) -> Self {
|
||||
log::error!("{}\n", error);
|
||||
tracing::error!("{}\n", error);
|
||||
CLIError::ImportsDirectoryError(error)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<InputsDirectoryError> for CLIError {
|
||||
fn from(error: InputsDirectoryError) -> Self {
|
||||
log::error!("{}\n", error);
|
||||
tracing::error!("{}\n", error);
|
||||
CLIError::InputDirectoryError(error)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<InputFileError> for CLIError {
|
||||
fn from(error: InputFileError) -> Self {
|
||||
log::error!("{}\n", error);
|
||||
tracing::error!("{}\n", error);
|
||||
CLIError::InputFileError(error)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<LibFileError> for CLIError {
|
||||
fn from(error: LibFileError) -> Self {
|
||||
log::error!("{}\n", error);
|
||||
tracing::error!("{}\n", error);
|
||||
CLIError::LibFileError(error)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<LoginError> for CLIError {
|
||||
fn from(error: LoginError) -> Self {
|
||||
log::error!("{}\n", error);
|
||||
tracing::error!("{}\n", error);
|
||||
CLIError::LoginError(error)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<MainFileError> for CLIError {
|
||||
fn from(error: MainFileError) -> Self {
|
||||
log::error!("{}\n", error);
|
||||
tracing::error!("{}\n", error);
|
||||
CLIError::MainFileError(error)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ManifestError> for CLIError {
|
||||
fn from(error: ManifestError) -> Self {
|
||||
log::error!("{}\n", error);
|
||||
tracing::error!("{}\n", error);
|
||||
CLIError::ManifestError(error)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<NewError> for CLIError {
|
||||
fn from(error: NewError) -> Self {
|
||||
log::error!("{}\n", error);
|
||||
tracing::error!("{}\n", error);
|
||||
CLIError::NewError(error)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<OutputsDirectoryError> for CLIError {
|
||||
fn from(error: OutputsDirectoryError) -> Self {
|
||||
log::error!("{}\n", error);
|
||||
tracing::error!("{}\n", error);
|
||||
CLIError::OutputDirectoryError(error)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ProofFileError> for CLIError {
|
||||
fn from(error: ProofFileError) -> Self {
|
||||
log::error!("{}\n", error);
|
||||
tracing::error!("{}\n", error);
|
||||
CLIError::ProofFileError(error)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ProvingKeyFileError> for CLIError {
|
||||
fn from(error: ProvingKeyFileError) -> Self {
|
||||
log::error!("{}\n", error);
|
||||
tracing::error!("{}\n", error);
|
||||
CLIError::ProvingKeyFileError(error)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<PublishError> for CLIError {
|
||||
fn from(error: PublishError) -> Self {
|
||||
log::error!("{}\n", error);
|
||||
tracing::error!("{}\n", error);
|
||||
CLIError::PublishError(error)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<READMEError> for CLIError {
|
||||
fn from(error: READMEError) -> Self {
|
||||
log::error!("{}\n", error);
|
||||
tracing::error!("{}\n", error);
|
||||
CLIError::READMEError(error)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<RunError> for CLIError {
|
||||
fn from(error: RunError) -> Self {
|
||||
log::error!("{}\n", error);
|
||||
tracing::error!("{}\n", error);
|
||||
CLIError::RunError(error)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<SourceDirectoryError> for CLIError {
|
||||
fn from(error: SourceDirectoryError) -> Self {
|
||||
log::error!("{}\n", error);
|
||||
tracing::error!("{}\n", error);
|
||||
CLIError::SourceDirectoryError(error)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<StateFileError> for CLIError {
|
||||
fn from(error: StateFileError) -> Self {
|
||||
log::error!("{}\n", error);
|
||||
tracing::error!("{}\n", error);
|
||||
CLIError::StateFileError(error)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<TestError> for CLIError {
|
||||
fn from(error: TestError) -> Self {
|
||||
log::error!("{}\n", error);
|
||||
tracing::error!("{}\n", error);
|
||||
CLIError::TestError(error)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<VerificationKeyFileError> for CLIError {
|
||||
fn from(error: VerificationKeyFileError) -> Self {
|
||||
log::error!("{}\n", error);
|
||||
tracing::error!("{}\n", error);
|
||||
CLIError::VerificationKeyFileError(error)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<leo_compiler::errors::CompilerError> 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<leo_input::errors::InputParserError> 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<reqwest::Error> for CLIError {
|
||||
fn from(error: reqwest::Error) -> Self {
|
||||
log::error!("{}\n", error);
|
||||
tracing::error!("{}\n", error);
|
||||
CLIError::Crate("rewquest", format!("{}", error))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<snarkos_errors::algorithms::snark::SNARKError> 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<snarkos_errors::gadgets::SynthesisError> 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<serde_json::error::Error> 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<std::io::Error> for CLIError {
|
||||
fn from(error: std::io::Error) -> Self {
|
||||
log::error!("{}\n", error);
|
||||
tracing::error!("{}\n", error);
|
||||
CLIError::Crate("std::io", format!("{}", error))
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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" }
|
||||
|
@ -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(())
|
||||
}
|
||||
|
@ -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(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user