🚩 Añade feature "testing"
- Permite desactivar trazas y registro de eventos al ejecutar tests. - Añade opción de configuración para activar o desactivar las trazas.
This commit is contained in:
parent
432caf292f
commit
500f69fa4f
7 changed files with 416 additions and 12 deletions
|
@ -12,6 +12,7 @@ include_config!(SETTINGS: Settings => [
|
|||
"app.startup_banner" => "Slant",
|
||||
|
||||
// [log]
|
||||
"log.enabled" => true,
|
||||
"log.tracing" => "Info",
|
||||
"log.rolling" => "Stdout",
|
||||
"log.path" => "log",
|
||||
|
@ -52,6 +53,8 @@ pub struct App {
|
|||
#[derive(Debug, Deserialize)]
|
||||
/// Sección `[log]` de la configuración. Forma parte de [`Settings`].
|
||||
pub struct Log {
|
||||
/// Gestión de trazas y registro de eventos activado (`true`) o desactivado (`false`).
|
||||
pub enabled: bool,
|
||||
/// Opciones, o combinación de opciones separadas por comas, para filtrar las trazas: *"Error"*,
|
||||
/// *"Warn"*, *"Info"*, *"Debug"* o *"Trace"*.
|
||||
/// Ejemplo: "Error,actix_server::builder=Info,tracing_actix_web=Debug".
|
||||
|
|
|
@ -35,6 +35,14 @@ use std::sync::LazyLock;
|
|||
/// envíen antes de finalizar la ejecución.
|
||||
#[rustfmt::skip]
|
||||
pub(crate) static TRACING: LazyLock<WorkerGuard> = LazyLock::new(|| {
|
||||
if !global::SETTINGS.log.enabled || cfg!(test) || cfg!(feature = "testing") {
|
||||
// Tracing desactivado, se instala un subscriber nulo.
|
||||
tracing::subscriber::set_global_default(tracing::subscriber::NoSubscriber::default())
|
||||
.expect("Failed to install global NoSubscriber (tracing disabled)");
|
||||
let (_, guard) = tracing_appender::non_blocking(std::io::sink());
|
||||
return guard;
|
||||
}
|
||||
|
||||
let env_filter = EnvFilter::try_new(&global::SETTINGS.log.tracing)
|
||||
.unwrap_or_else(|_| EnvFilter::new("Info"));
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue