🥅 Tracing messages always in default language
This commit is contained in:
parent
cb87b11845
commit
63299dc3e0
5 changed files with 15 additions and 69 deletions
|
|
@ -114,8 +114,6 @@ pub fn init_modules() {
|
||||||
#[cfg(feature = "database")]
|
#[cfg(feature = "database")]
|
||||||
pub fn run_migrations() {
|
pub fn run_migrations() {
|
||||||
if let Some(dbconn) = &*DBCONN {
|
if let Some(dbconn) = &*DBCONN {
|
||||||
use crate::locale::L10n;
|
|
||||||
|
|
||||||
if let Err(e) = run_now({
|
if let Err(e) = run_now({
|
||||||
struct Migrator;
|
struct Migrator;
|
||||||
impl MigratorTrait for Migrator {
|
impl MigratorTrait for Migrator {
|
||||||
|
|
@ -129,9 +127,7 @@ pub fn run_migrations() {
|
||||||
}
|
}
|
||||||
Migrator::up(SchemaManagerConnection::Connection(dbconn), None)
|
Migrator::up(SchemaManagerConnection::Connection(dbconn), None)
|
||||||
}) {
|
}) {
|
||||||
L10n::l("db_migration_fail")
|
trace::error!("Database upgrade failed ({})", e);
|
||||||
.with_arg("dberr", format!("{}", e))
|
|
||||||
.error();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Err(e) = run_now({
|
if let Err(e) = run_now({
|
||||||
|
|
@ -147,9 +143,7 @@ pub fn run_migrations() {
|
||||||
}
|
}
|
||||||
Migrator::down(SchemaManagerConnection::Connection(dbconn), None)
|
Migrator::down(SchemaManagerConnection::Connection(dbconn), None)
|
||||||
}) {
|
}) {
|
||||||
L10n::l("db_migration_fail")
|
trace::error!("Database downgrade failed ({})", e);
|
||||||
.with_arg("dberr", format!("{}", e))
|
|
||||||
.error();
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
//! Acceso unificado y normalizado a base de datos.
|
//! Acceso unificado y normalizado a base de datos.
|
||||||
|
|
||||||
use crate::locale::L10n;
|
|
||||||
use crate::{config, trace, LazyStatic};
|
use crate::{config, trace, LazyStatic};
|
||||||
|
|
||||||
pub use url::Url as DbUri;
|
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;
|
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(|| {
|
pub(crate) static DBCONN: LazyStatic<Option<DbConn>> = LazyStatic::new(|| {
|
||||||
if !config::SETTINGS.database.db_name.trim().is_empty() {
|
if !config::SETTINGS.database.db_name.trim().is_empty() {
|
||||||
trace::info!(
|
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.max_connections(config::SETTINGS.database.max_pool_size);
|
||||||
db_opt
|
db_opt
|
||||||
}))
|
}))
|
||||||
.unwrap_or_else(|_| panic!("{}", L10n::l("db_connection_fail").to_string())),
|
.unwrap_or_else(|_| panic!("Failed to connect to database")),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
|
@ -92,9 +93,7 @@ pub async fn query<Q: QueryStatementWriter>(stmt: &mut Q) -> Result<Vec<QueryRes
|
||||||
))
|
))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
None => Err(DbErr::Conn(RuntimeErr::Internal(
|
None => Err(DbErr::Conn(RuntimeErr::Internal(DBCONN_NOT_INITIALIZED.to_owned()))),
|
||||||
L10n::l("db_connection_not_initialized").debug(),
|
|
||||||
))),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -113,9 +112,7 @@ pub async fn exec<Q: QueryStatementWriter>(stmt: &mut Q) -> Result<Option<QueryR
|
||||||
))
|
))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
None => Err(DbErr::Conn(RuntimeErr::Internal(
|
None => Err(DbErr::Conn(RuntimeErr::Internal(DBCONN_NOT_INITIALIZED.to_owned()))),
|
||||||
L10n::l("db_connection_not_initialized").debug(),
|
|
||||||
))),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -127,9 +124,7 @@ pub async fn exec_raw(stmt: String) -> Result<ExecResult, DbErr> {
|
||||||
.execute(Statement::from_string(dbbackend, stmt))
|
.execute(Statement::from_string(dbbackend, stmt))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
None => Err(DbErr::Conn(RuntimeErr::Internal(
|
None => Err(DbErr::Conn(RuntimeErr::Internal(DBCONN_NOT_INITIALIZED.to_owned()))),
|
||||||
L10n::l("db_connection_not_initialized").debug(),
|
|
||||||
))),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -88,7 +88,7 @@
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
use crate::html::{Markup, PreEscaped};
|
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 fluent_templates;
|
||||||
pub use unic_langid::LanguageIdentifier;
|
pub use unic_langid::LanguageIdentifier;
|
||||||
|
|
@ -129,9 +129,12 @@ pub fn langid_for(language: impl Into<String>) -> Result<&'static LanguageIdenti
|
||||||
if language.is_empty() {
|
if language.is_empty() {
|
||||||
Ok(&LANGID_FALLBACK)
|
Ok(&LANGID_FALLBACK)
|
||||||
} else {
|
} else {
|
||||||
Err(L10n::l(LANGUAGE_SET_FAILURE)
|
Err(format!(
|
||||||
.with_arg("language", config::SETTINGS.app.language.as_str())
|
"{} Unicode Language Identifier \"{}\" is not accepted. {}",
|
||||||
.debug())
|
"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 {
|
pub fn escaped(&self, langid: &LanguageIdentifier) -> Markup {
|
||||||
PreEscaped(self.using(langid).unwrap_or_default())
|
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 {
|
impl ToString for L10n {
|
||||||
|
|
|
||||||
|
|
@ -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})
|
|
||||||
|
|
@ -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})
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue