Skip to content

Commit

Permalink
fix: logs should go to stdout not stderr (#153)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-camuto authored Mar 7, 2023
1 parent 57e5b0d commit ec40a77
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 27 deletions.
34 changes: 19 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ serde = { version = "1.0.126", features = ["derive"], optional = true }
serde_json = { version = "1.0.64", optional = true }
log = { version = "0.4.17", optional = true }
tabled = { version = "0.9.0", optional = true}
colog = { version = "1.1.0", optional = true }
eq-float = "0.1.0"
thiserror = "1.0.38"
hex = "0.4.3"
Expand All @@ -31,6 +30,10 @@ ethers = "1.0.2"
ethers-solc = "1.0.2"
tokio = { version = "1.22.0", features = ["macros"] }
regex = "1"
chrono = { version = "0.4.23", optional = true}
colored = { version = "2.0.0", optional = true}
env_logger = { version = "0.10.0", optional = true}
colored_json = { version = "3.0.1", optional = true}

[dev-dependencies]
criterion = {version = "0.3", features = ["html_reports"]}
Expand Down Expand Up @@ -69,4 +72,4 @@ default = ["ezkl"]
render = ["halo2_proofs/dev-graph", "plotters"]
tensorflow = ["dep:tensorflow"]
onnx = ["dep:tract-onnx"]
ezkl = ["onnx", "serde", "serde_json", "log", "colog", "tabled"]
ezkl = ["onnx", "serde", "serde_json", "log", "chrono", "colored", "env_logger", "tabled", "colored_json"]
1 change: 0 additions & 1 deletion benches/affine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ impl<F: FieldExt + TensorType> Circuit<F> for MyCircuit<F> {
}

fn runaffine(c: &mut Criterion) {
colog::init();
let mut group = c.benchmark_group("affine");
for &len in [4, 8, 16, 32, 64].iter() {
unsafe {
Expand Down
1 change: 0 additions & 1 deletion benches/cnvrl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ where
}

fn runcnvrl(c: &mut Criterion) {
colog::init();
let mut group = c.benchmark_group("cnvrl");

for size in [1, 2, 4].iter() {
Expand Down
1 change: 0 additions & 1 deletion benches/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ impl<F: FieldExt + TensorType> Circuit<F> for MyCircuit<F> {
}

fn runrange(c: &mut Criterion) {
colog::init();
let mut group = c.benchmark_group("range");
for &len in [4, 8, 16, 32, 64, 128].iter() {
unsafe {
Expand Down
1 change: 0 additions & 1 deletion benches/relu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ impl<F: FieldExt + TensorType> Circuit<F> for NLCircuit<F> {
}

fn runrelu(c: &mut Criterion) {
colog::init();
let mut group = c.benchmark_group("relu");

let mut rng = rand::thread_rng();
Expand Down
77 changes: 74 additions & 3 deletions src/bin/ezkl.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,84 @@
use chrono::Local;
use colored::*;
use colored_json::prelude::*;
use env_logger::Builder;
use ezkl::commands::Cli;
use ezkl::execute::run;
use log::{error, info};
use log::{error, info, Level, LevelFilter, Record};
use rand::seq::SliceRandom;
use std::env;
use std::error::Error;
use std::fmt::Formatter;
use std::io::Write;

#[allow(dead_code)]
pub fn level_color(level: &log::Level, msg: &str) -> String {
match level {
Level::Error => msg.red(),
Level::Warn => msg.yellow(),
Level::Info => msg.green(),
Level::Debug => msg.green(),
Level::Trace => msg.magenta(),
}
.bold()
.to_string()
}

fn level_token(level: &Level) -> &str {
match *level {
Level::Error => "E",
Level::Warn => "W",
Level::Info => "*",
Level::Debug => "D",
Level::Trace => "T",
}
}

fn prefix_token(level: &Level) -> String {
format!(
"{}{}{}",
"[".blue().bold(),
level_color(level, level_token(level)),
"]".blue().bold()
)
}

pub fn format(buf: &mut Formatter, record: &Record<'_>) -> Result<(), std::fmt::Error> {
let sep = format!("\n{} ", " | ".white().bold());
writeln!(
buf,
"{} {}",
prefix_token(&record.level()),
format!("{}", record.args()).replace("\n", &sep),
)
}

pub fn init_logger() {
let mut builder = Builder::new();
builder.format(|buf, record| {
writeln!(
buf,
"{} [{}, {}] - {}",
prefix_token(&record.level()),
Local::now().format("%Y-%m-%dT%H:%M:%S"),
record.metadata().target(),
format!("{}", record.args()).replace("\n", &format!("\n{} ", " | ".white().bold())),
)
});
builder.target(env_logger::Target::Stdout);
builder.filter(None, LevelFilter::Info);
if env::var("RUST_LOG").is_ok() {
builder.parse_filters(&env::var("RUST_LOG").unwrap());
}
builder.init();
}

#[tokio::main]
pub async fn main() -> Result<(), Box<dyn Error>> {
let args = Cli::create().unwrap();
colog::init();
init_logger();
banner();
info!("{}", &args.as_json()?);
info!("command: \n {}", &args.as_json()?.to_colored_json_auto()?);
let res = run(args).await;
match &res {
Ok(_) => info!("succeeded"),
Expand All @@ -32,6 +101,7 @@ fn banner() {
"{}",
format!(
"
███████╗███████╗██╗ ██╗██╗
██╔════╝╚══███╔╝██║ ██╔╝██║
█████╗ ███╔╝ █████╔╝ ██║
Expand All @@ -42,6 +112,7 @@ fn banner() {
-----------------------------------------------------------
Easy Zero Knowledge {}.
-----------------------------------------------------------
",
ell.choose(&mut rand::thread_rng()).unwrap()
)
Expand Down
4 changes: 1 addition & 3 deletions src/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,10 @@ fn derive_key(mnemonic: &str, path: &str, index: u32) -> Result<U256, Bytes> {
.build()
.map_err(|err| err.to_string().encode())?;

info!("Wallet key we use: {:#?}", wallet);
info!("wallet address: {:#?}", wallet.address());

let private_key = U256::from_big_endian(wallet.signer().to_bytes().as_slice());

info!("Private key we use: {:#?}", private_key);

Ok(private_key)
}

Expand Down

0 comments on commit ec40a77

Please sign in to comment.