Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 225 #254

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,4 @@ derive_more = { version = "1.0.0", features = [
"deref",
"display",
] }
time = { version = "0.3", features = ["formatting"] }
7 changes: 4 additions & 3 deletions bin/pbs.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use cb_common::{
config::load_pbs_config,
utils::{initialize_pbs_tracing_log, wait_for_signal},
config::{load_pbs_config, PBS_MODULE_NAME},
logging::initialize_tracing_log,
utils::wait_for_signal,
};
use cb_pbs::{DefaultBuilderApi, PbsService, PbsState};
use eyre::Result;
Expand All @@ -14,7 +15,7 @@ async fn main() -> Result<()> {
if std::env::var_os("RUST_BACKTRACE").is_none() {
std::env::set_var("RUST_BACKTRACE", "1");
}
let _guard = initialize_pbs_tracing_log();
let _guard = initialize_tracing_log(PBS_MODULE_NAME);

let pbs_config = load_pbs_config().await?;

Expand Down
3 changes: 2 additions & 1 deletion bin/signer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use cb_common::{
config::{StartSignerConfig, SIGNER_MODULE_NAME},
utils::{initialize_tracing_log, wait_for_signal},
logging::initialize_tracing_log,
utils::wait_for_signal,
};
use cb_signer::service::SigningService;
use eyre::Result;
Expand Down
8 changes: 3 additions & 5 deletions bin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@ pub mod prelude {
},
config::{
load_builder_module_config, load_commit_module_config, load_pbs_config,
load_pbs_custom_config, LogsSettings, StartCommitModuleConfig,
load_pbs_custom_config, LogsSettings, StartCommitModuleConfig, PBS_MODULE_NAME,
},
logging::initialize_tracing_log,
pbs::{BuilderEvent, BuilderEventClient, OnBuilderApiEvent},
signer::{BlsPublicKey, BlsSignature, EcdsaPublicKey, EcdsaSignature},
types::Chain,
utils::{
initialize_pbs_tracing_log, initialize_tracing_log, utcnow_ms, utcnow_ns, utcnow_sec,
utcnow_us,
},
utils::{utcnow_ms, utcnow_ns, utcnow_sec, utcnow_us},
};
pub use cb_metrics::provider::MetricsProvider;
pub use cb_pbs::{
Expand Down
6 changes: 6 additions & 0 deletions config.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,9 @@ log_level = "debug"
# Maximum number of log files to keep
# OPTIONAL
max_log_files = 30
# Log format. Supported values: default,json, raw
# OPTIONAL, DEFAULT: default
format = "raw"
# Log destination. Supported values: stdout, file, both
# OPTIONAL, DEFAULT: stdout
destination = "both"
4 changes: 4 additions & 0 deletions crates/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ url.workspace = true
rand.workspace = true
bimap.workspace = true
derive_more.workspace = true
time.workspace = true

unicode-normalization.workspace = true
base64.workspace = true

[dev-dependencies]
tempfile = "3.8"
57 changes: 47 additions & 10 deletions crates/common/src/config/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,28 @@ use std::path::PathBuf;

use eyre::Result;
use serde::{Deserialize, Serialize};
use tracing_subscriber::{fmt, Layer, Registry};

use super::{load_optional_env_var, CommitBoostConfig, LOGS_DIR_DEFAULT, LOGS_DIR_ENV};
use crate::logging::RawFormatter;

#[derive(Clone, Debug, Deserialize, Serialize, Default)]
#[serde(rename_all = "lowercase")]
pub enum LogFormat {
#[default]
Default, // default tracing format
Raw, // key=value format
Json, // JSON format
}

#[derive(Clone, Debug, Deserialize, Serialize, Default)]
#[serde(rename_all = "lowercase")]
pub enum LogDest {
Stdout, // Only console output
File, // Only file output
#[default]
Both, // Both console and file output
}

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct LogsSettings {
Expand All @@ -13,16 +33,10 @@ pub struct LogsSettings {
pub log_level: String,
#[serde(default)]
pub max_log_files: Option<usize>,
}

impl Default for LogsSettings {
fn default() -> Self {
LogsSettings {
log_dir_path: default_log_dir_path(),
log_level: default_log_level(),
max_log_files: None,
}
}
#[serde(default)]
pub format: LogFormat,
#[serde(default)]
pub destination: LogDest,
}

impl LogsSettings {
Expand All @@ -38,6 +52,29 @@ impl LogsSettings {

Ok(config.logs)
}

/// Creates a format layer based on the configured format type
pub fn create_format_layer(&self) -> Box<dyn Layer<Registry> + Send + Sync> {
match self.format {
LogFormat::Default => Box::new(fmt::layer().with_target(false)),
LogFormat::Raw => Box::new(fmt::layer().with_target(false).event_format(RawFormatter)),
LogFormat::Json => {
Box::new(fmt::layer().with_target(false).json().with_current_span(true))
}
}
}
}

impl Default for LogsSettings {
fn default() -> Self {
LogsSettings {
log_dir_path: default_log_dir_path(),
log_level: default_log_level(),
max_log_files: None,
format: LogFormat::default(),
destination: LogDest::default(),
}
}
}

fn default_log_dir_path() -> PathBuf {
Expand Down
1 change: 1 addition & 0 deletions crates/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pub mod commit;
pub mod config;
pub mod constants;
pub mod error;
pub mod logging;
pub mod pbs;
pub mod signature;
pub mod signer;
Expand Down
Loading
Loading