Añade seguimiento de la traza de ejecución
This commit is contained in:
parent
5d2901d32a
commit
cb557f4a86
7 changed files with 57 additions and 12 deletions
|
|
@ -30,6 +30,12 @@ figlet-rs = "0.1.3"
|
||||||
|
|
||||||
config_rs = { package = "config", version = "0.11.0", features = ["toml"] }
|
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"
|
fluent-templates = "0.6.1"
|
||||||
unic-langid = "0.9.0"
|
unic-langid = "0.9.0"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,11 @@ description = "Developed with the amazing PageTop framework."
|
||||||
language = "en-US"
|
language = "en-US"
|
||||||
# Tema predeterminado.
|
# Tema predeterminado.
|
||||||
theme = "Minimal"
|
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"
|
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]
|
[webserver]
|
||||||
# Configuración opcional del servidor web.
|
# Configuración opcional del servidor web.
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,7 @@ pub struct App {
|
||||||
pub language : String,
|
pub language : String,
|
||||||
pub theme : String,
|
pub theme : String,
|
||||||
pub startup_banner: String,
|
pub startup_banner: String,
|
||||||
|
pub tracing : String,
|
||||||
pub run_mode : String,
|
pub run_mode : String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -102,6 +103,7 @@ Ajustes globales y valores predeterminados para las secciones *\[app\]* y
|
||||||
"app.language" => "en-US",
|
"app.language" => "en-US",
|
||||||
"app.theme" => "Minimal",
|
"app.theme" => "Minimal",
|
||||||
"app.startup_banner" => "Small",
|
"app.startup_banner" => "Small",
|
||||||
|
"app.tracing" => "Info",
|
||||||
|
|
||||||
// [webserver]
|
// [webserver]
|
||||||
"webserver.bind_address" => "localhost",
|
"webserver.bind_address" => "localhost",
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,30 @@
|
||||||
use crate::base;
|
use crate::{base, trace};
|
||||||
use crate::config::SETTINGS;
|
use crate::config::SETTINGS;
|
||||||
use crate::core::{Server, all, register_module, server};
|
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> {
|
pub fn run(bootstrap: Option<fn()>) -> Result<Server, std::io::Error> {
|
||||||
// Ejecuta la función de arranque de la aplicación.
|
// Inicia el seguimiento de la traza de ejecución de la aplicación.
|
||||||
if bootstrap != None {
|
let env_filter = EnvFilter::try_new(String::from(&SETTINGS.app.tracing))
|
||||||
let _ = &(bootstrap.unwrap())();
|
.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.
|
// Imprime el rótulo (opcional) de bienvenida.
|
||||||
// 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.
|
|
||||||
if SETTINGS.app.startup_banner.to_lowercase() != "off" {
|
if SETTINGS.app.startup_banner.to_lowercase() != "off" {
|
||||||
let figfont = figlet_rs::FIGfont::from_content(
|
let figfont = figlet_rs::FIGfont::from_content(
|
||||||
match SETTINGS.app.startup_banner.to_lowercase().as_str() {
|
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"),
|
"small" => include_str!("../../../resources/small.flf"),
|
||||||
"speed" => include_str!("../../../resources/speed.flf"),
|
"speed" => include_str!("../../../resources/speed.flf"),
|
||||||
"starwars" => include_str!("../../../resources/starwars.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();
|
).unwrap();
|
||||||
println!("\n{} {}\n\n Powered by PageTop {}\n",
|
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.
|
// Inicializa el servidor web.
|
||||||
let server = server::HttpServer::new(|| {
|
let server = server::HttpServer::new(|| {
|
||||||
server::App::new()
|
server::App::new()
|
||||||
|
.wrap(TracingLogger)
|
||||||
.configure(&all::themes)
|
.configure(&all::themes)
|
||||||
.configure(&all::modules)
|
.configure(&all::modules)
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ pub use once_cell::sync::Lazy;
|
||||||
|
|
||||||
pub mod macros; // Macros útiles.
|
pub mod macros; // Macros útiles.
|
||||||
pub mod config; // Gestión de la configuración.
|
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 locale; // Localización.
|
||||||
pub mod core; // Servidor web y sistemas para Temas, Módulos y Respuestas.
|
pub mod core; // Servidor web y sistemas para Temas, Módulos y Respuestas.
|
||||||
pub mod base; // Temas, Módulos y Componentes base.
|
pub mod base; // Temas, Módulos y Componentes base.
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,8 @@
|
||||||
pub use crate::args;
|
pub use crate::args;
|
||||||
pub use crate::localize;
|
pub use crate::localize;
|
||||||
|
|
||||||
|
pub use crate::trace;
|
||||||
|
|
||||||
pub use crate::core::theme::*;
|
pub use crate::core::theme::*;
|
||||||
|
|
||||||
pub use crate::core::module::*;
|
pub use crate::core::module::*;
|
||||||
|
|
|
||||||
1
src/trace/mod.rs
Normal file
1
src/trace/mod.rs
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
pub use tracing::{debug, error, info, trace, warn};
|
||||||
Loading…
Add table
Add a link
Reference in a new issue