log + help: improved

This commit is contained in:
nym21
2026-01-29 11:54:38 +01:00
parent e01bb53b2e
commit 54827cd0a2
5 changed files with 113 additions and 30 deletions
+18 -6
View File
@@ -11,18 +11,16 @@ Command-line interface for running a Bitcoin Research Kit instance.
- Bitcoin Core running with RPC enabled
- Access to `blk*.dat` files
- ~400 GB disk space
- 12+ GB RAM
- [~400 GB disk space](https://bitview.space/api/server/disk)
- [12+ GB RAM](https://github.com/bitcoinresearchkit/benches#benchmarks)
## Install
```bash
rustup update
RUSTFLAGS="-C target-cpu=native" cargo install --locked brk_cli --version "$(cargo search brk_cli | head -1 | awk -F'"' '{print $2}')"
RUSTFLAGS="-C target-cpu=native" cargo install --locked brk_cli"
```
The SIMD flags (`bmi1`, `bmi2`, `avx2`) significantly improve pcodec decompression performance.
Portable build (without native CPU optimizations):
```bash
@@ -46,7 +44,21 @@ brk -h # Show all options
brk -V # Show version
```
Options are saved to `~/.brk/config.toml` after first use.
Command-line options override `~/.brk/config.toml` for that run only. Edit the file directly to persist settings:
```toml
brkdir = "/path/to/data"
bitcoindir = "/path/to/.bitcoin"
```
All fields are optional. See `brk -h` for the full list.
## Environment Variables
```bash
LOG=debug brk # Enable debug logging (keeps noise filters)
RUST_LOG=... brk # Full control over log filtering (overrides all defaults)
```
## Files
+86 -22
View File
@@ -4,11 +4,11 @@ use std::{
};
use brk_error::{Error, Result};
use owo_colors::OwoColorize;
use brk_fetcher::Fetcher;
use brk_rpc::{Auth, Client};
use brk_server::Website;
use brk_types::Port;
use owo_colors::OwoColorize;
use serde::{Deserialize, Deserializer, Serialize};
use crate::{default_brk_path, dot_brk_path, fix_user_path};
@@ -97,8 +97,6 @@ impl Config {
config.check();
config.write(&path)?;
Ok(config)
}
@@ -156,25 +154,96 @@ impl Config {
println!("Bitcoin Research Kit");
println!();
println!("{}", "USAGE:".bold());
println!(" brk {}", "[OPTIONS]".bright_black());
println!(
" {} brk {}",
"[ENV]".bright_black(),
"[OPTIONS]".bright_black()
);
println!();
println!("{}", "OPTIONS:".bold());
println!(" -h, --help Print help");
println!(" -V, --version Print version");
println!(" -h, --help Print help");
println!(" -V, --version Print version");
println!();
println!(" --brkdir {} Output directory {}", "<PATH>".bright_black(), "[~/.brk]".bright_black());
println!(" --brkport {} Server port {}", "<PORT>".bright_black(), "[3110]".bright_black());
println!(" --website {} Website: true, false, or path {}", "<BOOL|PATH>".bright_black(), "[true]".bright_black());
println!(" --fetch {} Fetch prices {}", "<BOOL>".bright_black(), "[true]".bright_black());
println!(
" --brkdir {} Output directory {}",
"<PATH>".bright_black(),
"[~/.brk]".bright_black()
);
println!(
" --brkport {} Server port {}",
"<PORT>".bright_black(),
"[3110]".bright_black()
);
println!(
" --website {} Website {}",
"<BOOL|PATH>".bright_black(),
"[true]".bright_black()
);
println!(
" --fetch {} Fetch prices {}",
"<BOOL>".bright_black(),
"[true]".bright_black()
);
println!();
println!(" --bitcoindir {} Bitcoin directory {}", "<PATH>".bright_black(), "[~/.bitcoin, ~/Library/...]".bright_black());
println!(" --blocksdir {} Blocks directory {}", "<PATH>".bright_black(), "[<bitcoindir>/blocks]".bright_black());
println!(
" --bitcoindir {} Bitcoin directory {}",
"<PATH>".bright_black(),
"[OS default]".bright_black()
);
println!(
" --blocksdir {} Blocks directory {}",
"<PATH>".bright_black(),
"[<bitcoindir>/blocks]".bright_black()
);
println!();
println!(" --rpcconnect {} RPC host {}", "<IP>".bright_black(), "[localhost]".bright_black());
println!(" --rpcport {} RPC port {}", "<PORT>".bright_black(), "[8332]".bright_black());
println!(" --rpccookiefile {} RPC cookie file {}", "<PATH>".bright_black(), "[<bitcoindir>/.cookie]".bright_black());
println!(" --rpcuser {} RPC username", "<USERNAME>".bright_black());
println!(" --rpcpassword {} RPC password", "<PASSWORD>".bright_black());
println!(
" --rpcconnect {} RPC host {}",
"<IP>".bright_black(),
"[localhost]".bright_black()
);
println!(
" --rpcport {} RPC port {}",
"<PORT>".bright_black(),
"[8332]".bright_black()
);
println!(
" --rpccookiefile {} RPC cookie file {}",
"<PATH>".bright_black(),
"[<bitcoindir>/.cookie]".bright_black()
);
println!(
" --rpcuser {} RPC username",
"<USERNAME>".bright_black()
);
println!(
" --rpcpassword {} RPC password",
"<PASSWORD>".bright_black()
);
println!();
println!("{}", "ENVIRONMENT:".bold());
println!(
" LOG={} Log level {}",
"<LEVEL>".bright_black(),
"[info]".bright_black()
);
println!(
" RUST_LOG={} Full log filter",
"<RULES>".bright_black()
);
println!();
println!("{}", "CONFIG:".bold());
println!(
" Edit {} to persist settings:",
"~/.brk/config.toml".bright_black()
);
println!(
" {}",
"brkdir = \"/path/to/data\"".bright_black()
);
println!(
" {}",
"bitcoindir = \"/path/to/.bitcoin\"".bright_black()
);
}
fn check(&self) {
@@ -216,10 +285,6 @@ Finally, you can run the program with '-h' for help."
)
}
fn write(&self, path: &Path) -> std::io::Result<()> {
fs::write(path, toml::to_string(self).unwrap())
}
pub fn rpc(&self) -> Result<Client> {
Client::new(
&format!(
@@ -300,7 +365,6 @@ Finally, you can run the program with '-h' for help."
self.fetch()
.then(|| Fetcher::import(Some(self.harsdir().as_path())).unwrap())
}
}
fn default_on_error<'de, D, T>(deserializer: D) -> Result<T, D::Error>
+5
View File
@@ -13,6 +13,11 @@ Drop-in logging initialization that silences noisy dependencies (bitcoin, fjall,
- **Sensible defaults**: Pre-configured filters silence common verbose libraries
- **Timestamp formatting**: Uses system timezone via jiff
## Environment Variables
- `LOG` - Set log level (default: `info` in release, `debug` in dev). Example: `LOG=debug brk`
- `RUST_LOG` - Full control over filtering (overrides all defaults)
## Core API
```rust,ignore
+3 -1
View File
@@ -23,9 +23,11 @@ pub fn init(path: Option<&Path>) -> io::Result<()> {
#[cfg(not(debug_assertions))]
const DEFAULT_LEVEL: &str = "info";
let level = std::env::var("LOG").unwrap_or_else(|_| DEFAULT_LEVEL.to_string());
let filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| {
EnvFilter::new(format!(
"{DEFAULT_LEVEL},bitcoin=off,bitcoincore-rpc=off,fjall=off,brk_fjall=off,lsm_tree=off,brk_rolldown=off,rolldown=off,tracing=off,aide=off,rustls=off,notify=off,oxc_resolver=off,tower_http=off"
"{level},bitcoin=off,bitcoincore-rpc=off,fjall=off,brk_fjall=off,lsm_tree=off,brk_rolldown=off,rolldown=off,tracing=off,aide=off,rustls=off,notify=off,oxc_resolver=off,tower_http=off"
))
});
+1 -1
View File
@@ -43,7 +43,7 @@ impl Inner {
.to_zoned(tz::TimeZone::system())
.strftime("%Y-%m-%d")
.to_string();
self.dir.join(format!("{}.{}", self.prefix, date))
self.dir.join(format!("{}_{}.txt", self.prefix, date))
}
}