🥅 Tracing messages always in default language

This commit is contained in:
Manuel Cillero 2023-10-29 21:38:51 +01:00
parent cb87b11845
commit 63299dc3e0
5 changed files with 15 additions and 69 deletions

View file

@ -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);
};
}
}

View file

@ -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<Option<DbConn>> = LazyStatic::new(|| {
if !config::SETTINGS.database.db_name.trim().is_empty() {
trace::info!(
@ -70,7 +71,7 @@ pub(crate) static DBCONN: LazyStatic<Option<DbConn>> = 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<Q: QueryStatementWriter>(stmt: &mut Q) -> Result<Vec<QueryRes
))
.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()))),
}
}
@ -113,9 +112,7 @@ pub async fn exec<Q: QueryStatementWriter>(stmt: &mut Q) -> Result<Option<QueryR
))
.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()))),
}
}
@ -127,9 +124,7 @@ pub async fn exec_raw(stmt: String) -> Result<ExecResult, DbErr> {
.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()))),
}
}

View file

@ -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<String>) -> 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 {

View file

@ -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})

View file

@ -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})