From 322cd9b6bfb8ece140c951ec33a2d274e4578dfc Mon Sep 17 00:00:00 2001 From: Manuel Cillero Date: Sat, 13 Apr 2024 19:43:47 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A7=20Code=20tweaks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- STARTER.bin.Cargo.toml | 10 ++++------ STARTER.lib.Cargo.toml | 8 ++++---- src/app.rs | 6 +++--- src/core/package/definition.rs | 4 ++-- src/locale.rs | 4 ++-- src/trace.rs | 7 +++++-- 6 files changed, 20 insertions(+), 19 deletions(-) diff --git a/STARTER.bin.Cargo.toml b/STARTER.bin.Cargo.toml index 18314711..4ce1d03c 100644 --- a/STARTER.bin.Cargo.toml +++ b/STARTER.bin.Cargo.toml @@ -7,17 +7,15 @@ edition = "2021" # https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -# Opcional. Para configurar servicios usando las macros de Actix Web: -actix-web = "4" +# Si requiere acceso a base de datos (mysql, postgres y/o sqlite): +pagetop = { version = "0.0", features = ["mysql"], default-features = false } +# pagetop = "0.0" (en otro caso) + # Opcional. Para usar archivos y recursos binarios contenidos en el ejecutable: static-files = "0.2.3" # Opcional. Para serializar estructuras de datos: serde = { version = "1.0", features = ["derive"] } -# Si requiere acceso a base de datos (mysql, postgres y/o sqlite): -pagetop = { version = "0.0", features = ["mysql"], default-features = false } -# pagetop = "0.0" (en otro caso) - [build-dependencies] # Opcional. Para incluir archivos y recursos binarios en el ejecutable: pagetop-build = "0.0" diff --git a/STARTER.lib.Cargo.toml b/STARTER.lib.Cargo.toml index 7572d68d..26c4debe 100644 --- a/STARTER.lib.Cargo.toml +++ b/STARTER.lib.Cargo.toml @@ -7,15 +7,15 @@ edition = "2021" # https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +# Si requiere acceso a base de datos: +pagetop = { version = "0.0", features = ["database"], default-features = false } +# pagetop = "0.0" (en otro caso) + # Opcional. Para usar archivos y recursos binarios contenidos en la librería: static-files = "0.2.3" # Opcional. Para serializar estructuras de datos: serde = { version = "1.0", features = ["derive"] } -# Si requiere acceso a base de datos: -pagetop = { version = "0.0", features = ["database"], default-features = false } -# pagetop = "0.0" (en otro caso) - [build-dependencies] # Opcional. Para incluir archivos y recursos binarios en la propia librería: pagetop-build = "0.0" diff --git a/src/app.rs b/src/app.rs index 421137e5..19fcc8a2 100644 --- a/src/app.rs +++ b/src/app.rs @@ -59,13 +59,13 @@ impl Application { // Registers package actions. package::all::register_actions(); - // Initializes the packages. - package::all::init_packages(); - #[cfg(feature = "database")] // Runs pending database migrations. package::all::run_migrations(); + // Initializes the packages. + package::all::init_packages(); + Self } diff --git a/src/core/package/definition.rs b/src/core/package/definition.rs index bf3deab8..7ec0258a 100644 --- a/src/core/package/definition.rs +++ b/src/core/package/definition.rs @@ -35,13 +35,13 @@ pub trait PackageTrait: AnyBase + Send + Sync { actions![] } - fn init(&self) {} - #[cfg(feature = "database")] fn migrations(&self) -> Vec { migrations![] } + fn init(&self) {} + #[allow(unused_variables)] fn configure_service(&self, scfg: &mut service::web::ServiceConfig) {} } diff --git a/src/locale.rs b/src/locale.rs index a01f5f52..a323aa95 100644 --- a/src/locale.rs +++ b/src/locale.rs @@ -92,8 +92,8 @@ use crate::{config, kv, AutoDefault, LazyStatic, LOCALES_PAGETOP}; pub use fluent_templates; pub use unic_langid::LanguageIdentifier; -pub(crate) use fluent_templates::Loader; -pub(crate) use fluent_templates::StaticLoader as Locales; +use fluent_templates::Loader; +use fluent_templates::StaticLoader as Locales; use unic_langid::langid; diff --git a/src/trace.rs b/src/trace.rs index 2ebf6881..3758f263 100644 --- a/src/trace.rs +++ b/src/trace.rs @@ -36,10 +36,11 @@ use tracing_subscriber::EnvFilter; #[rustfmt::skip] pub(crate) static TRACING: LazyStatic = LazyStatic::new(|| { - let env_filter = - EnvFilter::try_new(&config::SETTINGS.log.tracing).unwrap_or_else(|_| EnvFilter::new("Info")); + let env_filter = EnvFilter::try_new(&config::SETTINGS.log.tracing) + .unwrap_or_else(|_| EnvFilter::new("Info")); let rolling = config::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({ @@ -60,10 +61,12 @@ pub(crate) static TRACING: LazyStatic = LazyStatic::new(|| { } }), }; + let subscriber = tracing_subscriber::fmt() .with_env_filter(env_filter) .with_writer(non_blocking) .with_ansi(rolling.as_str() == "stdout"); + match config::SETTINGS.log.format.to_lowercase().as_str() { "json" => subscriber.json().init(), "full" => subscriber.init(),