Skip to content

Commit

Permalink
Merge pull request #1944 from blockstack/feat/slogging
Browse files Browse the repository at this point in the history
Discussion: Structured logging via `slog`
  • Loading branch information
kantai authored Oct 26, 2020
2 parents 13e1648 + a3463ef commit edd559a
Show file tree
Hide file tree
Showing 12 changed files with 306 additions and 112 deletions.
141 changes: 141 additions & 0 deletions Cargo.lock

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

6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ percent-encoding = "2.1.0"
sha2 = "0.8.0"
prometheus = { version = "0.9", optional = true }
integer-sqrt = "0.1.3"
slog = "2.5.2"
slog-term = "2.6.0"
slog-json = { version = "2.3.0", optional = true }

[dependencies.serde_json]
version = "1.0"
Expand Down Expand Up @@ -88,10 +91,11 @@ assert-json-diff = "1.0.0"
criterion = "0.3"

[features]
developer-mode = []
default = ["developer-mode"]
developer-mode = []
monitoring_prom = ["prometheus"]
tx_log = []
slog_json = ["slog-json"]

[target.'cfg(all(target_arch = "x86_64", not(target_env = "msvc")))'.dependencies]
sha2-asm = "0.5.3"
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ RUN apk add --no-cache musl-dev

RUN mkdir /out

RUN cd testnet/stacks-node && cargo build --features "monitoring_prom" --release
RUN cd testnet/stacks-node && cargo build --features monitoring_prom,slog_json --release
RUN cd testnet/bitcoin-neon-controller && cargo build --release

RUN cp target/release/stacks-node /out
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.stretch
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ COPY . .

RUN mkdir /out

RUN cd testnet/stacks-node && cargo build --features "monitoring_prom" --release
RUN cd testnet/stacks-node && cargo build --features monitoring_prom,slog_json --release
RUN cd testnet/bitcoin-neon-controller && cargo build --release

RUN cp target/release/stacks-node /out
Expand Down
1 change: 0 additions & 1 deletion src/blockstack_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,6 @@ fn decode_block(args: &[String], _version: TransactionVersion) -> Result<String,
}

fn main() {
log::set_loglevel(log::LOG_DEBUG).unwrap();
let mut argv: Vec<String> = env::args().collect();

argv.remove(0);
Expand Down
2 changes: 1 addition & 1 deletion src/chainstate/stacks/index/marf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ impl<'a, T: MarfTrieId> MarfTransaction<'a, T> {
if !is_parent_sentinel {
debug!("Extending off of existing node {}", chain_tip);
} else {
info!("First-ever block {}", next_chain_tip);
info!("First-ever block {}", next_chain_tip; "block" => %next_chain_tip);
}

self.storage.open_block(chain_tip)?;
Expand Down
1 change: 0 additions & 1 deletion src/clarity_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ use blockstack_lib::{clarity, util::log};
use std::env;

fn main() {
log::set_loglevel(log::LOG_DEBUG).unwrap();
let argv: Vec<String> = env::args().collect();

clarity::invoke_command(&argv[0], &argv[1..]);
Expand Down
6 changes: 6 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ extern crate sha3;
extern crate time;
extern crate url;

#[macro_use(o, slog_log, slog_trace, slog_debug, slog_info, slog_warn, slog_error)]
extern crate slog;
#[cfg(feature = "slog_json")]
extern crate slog_json;
extern crate slog_term;

#[macro_use]
extern crate serde_derive;
#[macro_use]
Expand Down
5 changes: 3 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
extern crate blockstack_lib;
extern crate rusqlite;

#[macro_use(o, slog_log, slog_trace, slog_debug, slog_info, slog_warn, slog_error)]
extern crate slog;

use blockstack_lib::burnchains::db::BurnchainBlockData;
use blockstack_lib::*;

Expand Down Expand Up @@ -54,8 +57,6 @@ use rusqlite::Connection;
use rusqlite::OpenFlags;

fn main() {
log::set_loglevel(log::LOG_INFO).unwrap();

let mut argv: Vec<String> = env::args().collect();
if argv.len() < 2 {
eprintln!("Usage: {} command [args...]", argv[0]);
Expand Down
Loading

0 comments on commit edd559a

Please sign in to comment.