Añade seguimiento de la traza de ejecución

This commit is contained in:
Manuel Cillero 2022-02-14 22:52:41 +01:00
parent 5d2901d32a
commit cb557f4a86
7 changed files with 57 additions and 12 deletions

View file

@ -30,6 +30,12 @@ figlet-rs = "0.1.3"
config_rs = { package = "config", version = "0.11.0", features = ["toml"] }
tracing = "0.1"
tracing-log = "0.1"
tracing-subscriber = { version = "0.3", features = ["registry", "env-filter"] }
tracing-bunyan-formatter = "0.3"
tracing-actix-web = "0.2"
fluent-templates = "0.6.1"
unic-langid = "0.9.0"

View file

@ -5,8 +5,11 @@ description = "Developed with the amazing PageTop framework."
language = "en-US"
# Tema predeterminado.
theme = "Minimal"
# Rótulo al inicio: "Off", "Slant", "Small", "Speed" or "Starwars".
# Rótulo al inicio: "Off", "Slant", "Small", "Speed" o "Starwars".
startup_banner = "Small"
# Traza de la ejecución: "Error", "Warn", "Info", "Debug" o "Trace".
# Ejemplos: "Error,actix_server::builder=Info,tracing_actix_web=Debug".
tracing = "Info"
[webserver]
# Configuración opcional del servidor web.

View file

@ -75,6 +75,7 @@ pub struct App {
pub language : String,
pub theme : String,
pub startup_banner: String,
pub tracing : String,
pub run_mode : String,
}
@ -102,6 +103,7 @@ Ajustes globales y valores predeterminados para las secciones *\[app\]* y
"app.language" => "en-US",
"app.theme" => "Minimal",
"app.startup_banner" => "Small",
"app.tracing" => "Info",
// [webserver]
"webserver.bind_address" => "localhost",

View file

@ -1,18 +1,30 @@
use crate::base;
use crate::{base, trace};
use crate::config::SETTINGS;
use crate::core::{Server, all, register_module, server};
use tracing::subscriber::set_global_default;
use tracing_subscriber::{EnvFilter, Registry};
use tracing_subscriber::layer::SubscriberExt;
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> {
// Ejecuta la función de arranque de la aplicación.
if bootstrap != None {
let _ = &(bootstrap.unwrap())();
}
// 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")));
let formatting_layer = BunyanFormattingLayer::new(
String::from(&SETTINGS.app.name),
std::io::stdout
);
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");
// Registra el módulo para la página de inicio de PageTop.
// Al ser el último, puede sobrecargarse en la función de arranque.
register_module(&base::module::homepage::HomepageModule);
// Si el arranque ha ido bien imprime un rótulo opcional de bienvenida.
// Imprime el rótulo (opcional) de bienvenida.
if SETTINGS.app.startup_banner.to_lowercase() != "off" {
let figfont = figlet_rs::FIGfont::from_content(
match SETTINGS.app.startup_banner.to_lowercase().as_str() {
@ -20,7 +32,13 @@ pub fn run(bootstrap: Option<fn()>) -> Result<Server, std::io::Error> {
"small" => include_str!("../../../resources/small.flf"),
"speed" => include_str!("../../../resources/speed.flf"),
"starwars" => include_str!("../../../resources/starwars.flf"),
_ => include_str!("../../../resources/small.flf")
_ => {
trace::warn!(
">>> FIGfont \"{}\" not found for banner. Using \"{}\"",
SETTINGS.app.startup_banner, "Small"
);
include_str!("../../../resources/small.flf")
}
}
).unwrap();
println!("\n{} {}\n\n Powered by PageTop {}\n",
@ -30,9 +48,21 @@ pub fn run(bootstrap: Option<fn()>) -> Result<Server, std::io::Error> {
);
}
// Ejecuta la función de inicio de la aplicación.
if bootstrap != None {
trace::debug!("Calling application bootstrap");
let _ = &(bootstrap.unwrap())();
}
// Registra el módulo para la página de inicio de PageTop.
// Al ser el último, puede sobrecargarse en la función de arranque.
register_module(&base::module::homepage::HomepageModule);
// Inicializa el servidor web.
let server = server::HttpServer::new(|| {
server::App::new()
.wrap(TracingLogger)
.configure(&all::themes)
.configure(&all::modules)
})

View file

@ -9,6 +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 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.

View file

@ -3,6 +3,8 @@
pub use crate::args;
pub use crate::localize;
pub use crate::trace;
pub use crate::core::theme::*;
pub use crate::core::module::*;

1
src/trace/mod.rs Normal file
View file

@ -0,0 +1 @@
pub use tracing::{debug, error, info, trace, warn};