#[doc(hidden)]
mod console;
pub use console::*;
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct WasmLayerConfig {
pub report_logs_in_timings: bool,
pub console: ConsoleConfig,
pub max_level: tracing::Level,
pub show_fields: bool,
pub show_origin: bool,
pub origin_base_url: Option<String>,
}
impl Default for WasmLayerConfig {
fn default() -> Self {
WasmLayerConfig {
report_logs_in_timings: true,
console: ConsoleConfig::ReportWithConsoleColor,
max_level: tracing::Level::TRACE,
show_fields: true,
show_origin: true,
origin_base_url: None,
}
}
}
impl WasmLayerConfig {
pub fn new() -> WasmLayerConfig {
WasmLayerConfig::default()
}
pub fn set_report_logs_in_timings(&mut self, report_logs_in_timings: bool) -> &mut Self {
self.report_logs_in_timings = report_logs_in_timings;
self
}
pub fn set_max_level(&mut self, max_level: tracing::Level) -> &mut Self {
self.max_level = max_level;
self
}
pub fn set_console_config(&mut self, console_config: ConsoleConfig) -> &mut Self {
self.console = console_config;
self
}
pub fn set_show_origin(&mut self, show_origin: bool) -> &mut Self {
self.show_origin = show_origin;
self
}
pub fn set_show_fields(&mut self, show_fields: bool) -> &mut Self {
self.show_fields = show_fields;
self
}
pub fn set_origin_base_url(&mut self, origin_base_url: impl ToString) -> &mut Self {
self.origin_base_url = Some(origin_base_url.to_string());
self
}
pub fn console_enabled(&self) -> bool {
self.console.reporting_enabled()
}
}
#[test]
fn test_default_built_config() {
let config = WasmLayerConfig::new();
assert_eq!(
config,
WasmLayerConfig {
report_logs_in_timings: true,
console: ConsoleConfig::ReportWithConsoleColor,
max_level: tracing::Level::TRACE,
show_fields: true,
show_origin: true,
origin_base_url: None
}
)
}
#[test]
fn test_set_report_logs_in_timings() {
let mut config = WasmLayerConfig::new();
config.set_report_logs_in_timings(false);
assert!(!config.report_logs_in_timings);
}
#[test]
fn test_set_console_config_no_reporting() {
let mut config = WasmLayerConfig::new();
config.set_console_config(ConsoleConfig::NoReporting);
assert!(!config.console.reporting_enabled());
}
#[test]
fn test_set_console_config_without_color() {
let mut config = WasmLayerConfig::new();
config.set_console_config(ConsoleConfig::ReportWithoutConsoleColor);
assert_eq!(config.console, ConsoleConfig::ReportWithoutConsoleColor);
}
#[test]
fn test_set_console_config_with_color() {
let mut config = WasmLayerConfig::new();
config.set_console_config(ConsoleConfig::ReportWithConsoleColor);
assert_eq!(config.console, ConsoleConfig::ReportWithConsoleColor);
}
#[test]
fn test_set_config_log_level_warn() {
let mut config = WasmLayerConfig::new();
config.set_max_level(tracing::Level::WARN);
assert_eq!(config.max_level, tracing::Level::WARN);
}