From 63299dc3e057c113a674134a4d068954cfb3886a Mon Sep 17 00:00:00 2001 From: Manuel Cillero Date: Sun, 29 Oct 2023 21:38:51 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=A5=85=20Tracing=20messages=20always=20in?= =?UTF-8?q?=20default=20language?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pagetop/src/core/module/all.rs | 10 ++------ pagetop/src/db.rs | 17 +++++-------- pagetop/src/locale.rs | 41 +++++------------------------- pagetop/src/locale/en-US/trace.ftl | 8 ------ pagetop/src/locale/es-ES/trace.ftl | 8 ------ 5 files changed, 15 insertions(+), 69 deletions(-) delete mode 100644 pagetop/src/locale/en-US/trace.ftl delete mode 100644 pagetop/src/locale/es-ES/trace.ftl diff --git a/pagetop/src/core/module/all.rs b/pagetop/src/core/module/all.rs index ddbcd5b5..e4e2b923 100644 --- a/pagetop/src/core/module/all.rs +++ b/pagetop/src/core/module/all.rs @@ -114,8 +114,6 @@ pub fn init_modules() { #[cfg(feature = "database")] pub fn run_migrations() { if let Some(dbconn) = &*DBCONN { - use crate::locale::L10n; - if let Err(e) = run_now({ struct Migrator; impl MigratorTrait for Migrator { @@ -129,9 +127,7 @@ pub fn run_migrations() { } Migrator::up(SchemaManagerConnection::Connection(dbconn), None) }) { - L10n::l("db_migration_fail") - .with_arg("dberr", format!("{}", e)) - .error(); + trace::error!("Database upgrade failed ({})", e); }; if let Err(e) = run_now({ @@ -147,9 +143,7 @@ pub fn run_migrations() { } Migrator::down(SchemaManagerConnection::Connection(dbconn), None) }) { - L10n::l("db_migration_fail") - .with_arg("dberr", format!("{}", e)) - .error(); + trace::error!("Database downgrade failed ({})", e); }; } } diff --git a/pagetop/src/db.rs b/pagetop/src/db.rs index 4560b716..aac2e073 100644 --- a/pagetop/src/db.rs +++ b/pagetop/src/db.rs @@ -1,6 +1,5 @@ //! Acceso unificado y normalizado a base de datos. -use crate::locale::L10n; use crate::{config, trace, LazyStatic}; pub use url::Url as DbUri; @@ -12,6 +11,8 @@ use sea_orm::{ConnectOptions, ConnectionTrait, Database, DatabaseBackend, Statem pub(crate) use futures::executor::block_on as run_now; +const DBCONN_NOT_INITIALIZED: &str = "Database connection not initialized"; + pub(crate) static DBCONN: LazyStatic> = LazyStatic::new(|| { if !config::SETTINGS.database.db_name.trim().is_empty() { trace::info!( @@ -70,7 +71,7 @@ pub(crate) static DBCONN: LazyStatic> = LazyStatic::new(|| { db_opt.max_connections(config::SETTINGS.database.max_pool_size); db_opt })) - .unwrap_or_else(|_| panic!("{}", L10n::l("db_connection_fail").to_string())), + .unwrap_or_else(|_| panic!("Failed to connect to database")), ) } else { None @@ -92,9 +93,7 @@ pub async fn query(stmt: &mut Q) -> Result Err(DbErr::Conn(RuntimeErr::Internal( - L10n::l("db_connection_not_initialized").debug(), - ))), + None => Err(DbErr::Conn(RuntimeErr::Internal(DBCONN_NOT_INITIALIZED.to_owned()))), } } @@ -113,9 +112,7 @@ pub async fn exec(stmt: &mut Q) -> Result Err(DbErr::Conn(RuntimeErr::Internal( - L10n::l("db_connection_not_initialized").debug(), - ))), + None => Err(DbErr::Conn(RuntimeErr::Internal(DBCONN_NOT_INITIALIZED.to_owned()))), } } @@ -127,9 +124,7 @@ pub async fn exec_raw(stmt: String) -> Result { .execute(Statement::from_string(dbbackend, stmt)) .await } - None => Err(DbErr::Conn(RuntimeErr::Internal( - L10n::l("db_connection_not_initialized").debug(), - ))), + None => Err(DbErr::Conn(RuntimeErr::Internal(DBCONN_NOT_INITIALIZED.to_owned()))), } } diff --git a/pagetop/src/locale.rs b/pagetop/src/locale.rs index 55e6197b..8f9be238 100644 --- a/pagetop/src/locale.rs +++ b/pagetop/src/locale.rs @@ -88,7 +88,7 @@ //! ``` use crate::html::{Markup, PreEscaped}; -use crate::{config, kv, trace, LazyStatic, LOCALES_PAGETOP}; +use crate::{config, kv, LazyStatic, LOCALES_PAGETOP}; pub use fluent_templates; pub use unic_langid::LanguageIdentifier; @@ -129,9 +129,12 @@ pub fn langid_for(language: impl Into) -> Result<&'static LanguageIdenti if language.is_empty() { Ok(&LANGID_FALLBACK) } else { - Err(L10n::l(LANGUAGE_SET_FAILURE) - .with_arg("language", config::SETTINGS.app.language.as_str()) - .debug()) + Err(format!( + "{} Unicode Language Identifier \"{}\" is not accepted. {}", + "Failed to set language.", + config::SETTINGS.app.language, + "Using \"en-US\", check the settings file" + )) } } } @@ -239,36 +242,6 @@ impl L10n { pub fn escaped(&self, langid: &LanguageIdentifier) -> Markup { PreEscaped(self.using(langid).unwrap_or_default()) } - - pub fn trace(&self) -> String { - let message = self.to_string(); - trace::trace!(message); - message - } - - pub fn debug(&self) -> String { - let message = self.to_string(); - trace::debug!(message); - message - } - - pub fn info(&self) -> String { - let message = self.to_string(); - trace::info!(message); - message - } - - pub fn warn(&self) -> String { - let message = self.to_string(); - trace::warn!(message); - message - } - - pub fn error(&self) -> String { - let message = self.to_string(); - trace::error!(message); - message - } } impl ToString for L10n { diff --git a/pagetop/src/locale/en-US/trace.ftl b/pagetop/src/locale/en-US/trace.ftl deleted file mode 100644 index f0cd654d..00000000 --- a/pagetop/src/locale/en-US/trace.ftl +++ /dev/null @@ -1,8 +0,0 @@ -# DEBUG. - -# ERRORS. -language_set_failure = Failed to set language. Unicode Language Identifier "{$language}" is not accepted. Using "en-US", check the settings file - -db_connection_fail = Failed to connect to database -db_connection_not_initialized = Database connection not initialized -db_migration_fail = Database update failed (${dberr}) diff --git a/pagetop/src/locale/es-ES/trace.ftl b/pagetop/src/locale/es-ES/trace.ftl deleted file mode 100644 index 4fdad1e9..00000000 --- a/pagetop/src/locale/es-ES/trace.ftl +++ /dev/null @@ -1,8 +0,0 @@ -# DEBUG. - -# ERRORS. -language_set_failure = Fallo al asignar idioma. El Identificador de Lenguaje Unicode "{$language}" no es válido. Se usará "en-US". Comprobar archivo de configuración - -db_connection_fail = Fallo al conectar con la base de datos -db_connection_not_initialized = Conexión a la base de datos no inicializada -db_migration_fail = Fallo al actualizar base de datos (${dberr})