Mejora la funcionalidad de la traza de ejecución
This commit is contained in:
parent
cb557f4a86
commit
1d438dff57
5 changed files with 64 additions and 15 deletions
|
|
@ -32,6 +32,7 @@ config_rs = { package = "config", version = "0.11.0", features = ["toml"] }
|
|||
|
||||
tracing = "0.1"
|
||||
tracing-log = "0.1"
|
||||
tracing-appender = "0.2"
|
||||
tracing-subscriber = { version = "0.3", features = ["registry", "env-filter"] }
|
||||
tracing-bunyan-formatter = "0.3"
|
||||
tracing-actix-web = "0.2"
|
||||
|
|
|
|||
|
|
@ -7,9 +7,17 @@ language = "en-US"
|
|||
theme = "Minimal"
|
||||
# Rótulo al inicio: "Off", "Slant", "Small", "Speed" o "Starwars".
|
||||
startup_banner = "Small"
|
||||
# Traza de la ejecución: "Error", "Warn", "Info", "Debug" o "Trace".
|
||||
|
||||
[log]
|
||||
# Traza de ejecución: "Error", "Warn", "Info", "Debug" o "Trace".
|
||||
# Ejemplos: "Error,actix_server::builder=Info,tracing_actix_web=Debug".
|
||||
tracing = "Info"
|
||||
# En terminal ("Stdout") o archivos "Daily", "Hourly", "Minutely" o "Endless".
|
||||
rolling = "Daily"
|
||||
# Directorio para los archivos de traza (si rolling != "Stdout").
|
||||
path = "log"
|
||||
# Prefijo para los archivos de traza (si rolling != "Stdout").
|
||||
prefix = "tracing.log"
|
||||
|
||||
[webserver]
|
||||
# Configuración opcional del servidor web.
|
||||
|
|
|
|||
|
|
@ -75,10 +75,17 @@ pub struct App {
|
|||
pub language : String,
|
||||
pub theme : String,
|
||||
pub startup_banner: String,
|
||||
pub tracing : String,
|
||||
pub run_mode : String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct Log {
|
||||
pub tracing : String,
|
||||
pub rolling : String,
|
||||
pub path : String,
|
||||
pub prefix : String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct Webserver {
|
||||
pub bind_address : String,
|
||||
|
|
@ -88,12 +95,13 @@ pub struct Webserver {
|
|||
#[derive(Debug, Deserialize)]
|
||||
pub struct Settings {
|
||||
pub app : App,
|
||||
pub log : Log,
|
||||
pub webserver : Webserver,
|
||||
}
|
||||
|
||||
config_map!(r#"
|
||||
Ajustes globales y valores predeterminados para las secciones *\[app\]* y
|
||||
*\[webserver\]* específicas de PageTop.
|
||||
Ajustes globales y valores predeterminados para las secciones *\[app\]*,
|
||||
*\[log\]* y *\[webserver\]* específicas de PageTop.
|
||||
"#,
|
||||
SETTINGS, Settings,
|
||||
|
||||
|
|
@ -103,7 +111,12 @@ Ajustes globales y valores predeterminados para las secciones *\[app\]* y
|
|||
"app.language" => "en-US",
|
||||
"app.theme" => "Minimal",
|
||||
"app.startup_banner" => "Small",
|
||||
"app.tracing" => "Info",
|
||||
|
||||
// [log]
|
||||
"log.tracing" => "Info",
|
||||
"log.rolling" => "Daily",
|
||||
"log.path" => "log",
|
||||
"log.prefix" => "tracing.log",
|
||||
|
||||
// [webserver]
|
||||
"webserver.bind_address" => "localhost",
|
||||
|
|
|
|||
|
|
@ -2,27 +2,54 @@ use crate::{base, trace};
|
|||
use crate::config::SETTINGS;
|
||||
use crate::core::{Server, all, register_module, server};
|
||||
|
||||
use tracing::subscriber::set_global_default;
|
||||
use tracing_log::LogTracer;
|
||||
use tracing_subscriber::{EnvFilter, Registry};
|
||||
use tracing_subscriber::layer::SubscriberExt;
|
||||
use tracing::subscriber::set_global_default;
|
||||
use tracing_bunyan_formatter::{BunyanFormattingLayer, JsonStorageLayer};
|
||||
use tracing_log::LogTracer;
|
||||
use tracing_actix_web::TracingLogger;
|
||||
|
||||
pub fn run(bootstrap: Option<fn()>) -> Result<Server, std::io::Error> {
|
||||
// Inicia el seguimiento de la traza de ejecución de la aplicación.
|
||||
let env_filter = EnvFilter::try_new(String::from(&SETTINGS.app.tracing))
|
||||
.unwrap_or(EnvFilter::new(String::from("Info")));
|
||||
// Inicia la traza de ejecución de la aplicación.
|
||||
let env_filter = EnvFilter::try_new(&SETTINGS.log.tracing)
|
||||
.unwrap_or(EnvFilter::new("Info"));
|
||||
|
||||
let rolling = SETTINGS.log.rolling.to_lowercase();
|
||||
let (non_blocking, _guard) = match rolling.as_str() {
|
||||
"stdout" => tracing_appender::non_blocking(
|
||||
std::io::stdout()
|
||||
),
|
||||
_ => tracing_appender::non_blocking({
|
||||
let path = &SETTINGS.log.path;
|
||||
let prefix = &SETTINGS.log.prefix;
|
||||
match rolling.as_str() {
|
||||
"daily" => tracing_appender::rolling::daily(path, prefix),
|
||||
"hourly" => tracing_appender::rolling::hourly(path, prefix),
|
||||
"minutely" => tracing_appender::rolling::minutely(path, prefix),
|
||||
"endless" => tracing_appender::rolling::never(path, prefix),
|
||||
_ => {
|
||||
println!(
|
||||
"Rolling value \"{}\" not valid. Using \"daily\"",
|
||||
rolling
|
||||
);
|
||||
tracing_appender::rolling::daily(path, prefix)
|
||||
}
|
||||
}
|
||||
})
|
||||
};
|
||||
let formatting_layer = BunyanFormattingLayer::new(
|
||||
String::from(&SETTINGS.app.name),
|
||||
std::io::stdout
|
||||
non_blocking
|
||||
);
|
||||
|
||||
let subscriber = Registry::default()
|
||||
.with(env_filter)
|
||||
.with(JsonStorageLayer)
|
||||
.with(formatting_layer);
|
||||
LogTracer::init().expect("Failed to set logger");
|
||||
set_global_default(subscriber).expect("Failed to set subscriber");
|
||||
|
||||
set_global_default(subscriber).expect("Unable to setup subscriber!");
|
||||
|
||||
LogTracer::init().expect("Unable to setup log tracer!");
|
||||
|
||||
// Imprime el rótulo (opcional) de bienvenida.
|
||||
if SETTINGS.app.startup_banner.to_lowercase() != "off" {
|
||||
|
|
@ -34,7 +61,7 @@ pub fn run(bootstrap: Option<fn()>) -> Result<Server, std::io::Error> {
|
|||
"starwars" => include_str!("../../../resources/starwars.flf"),
|
||||
_ => {
|
||||
trace::warn!(
|
||||
">>> FIGfont \"{}\" not found for banner. Using \"{}\"",
|
||||
"FIGfont \"{}\" not found for banner. Using \"{}\"",
|
||||
SETTINGS.app.startup_banner, "Small"
|
||||
);
|
||||
include_str!("../../../resources/small.flf")
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ pub use once_cell::sync::Lazy;
|
|||
|
||||
pub mod macros; // Macros útiles.
|
||||
pub mod config; // Gestión de la configuración.
|
||||
pub mod trace; // Seguimiento de la traza de ejecución.
|
||||
pub mod trace; // Traza de ejecución.
|
||||
pub mod locale; // Localización.
|
||||
pub mod core; // Servidor web y sistemas para Temas, Módulos y Respuestas.
|
||||
pub mod base; // Temas, Módulos y Componentes base.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue