Actualiza la inicialización de traza+localización
This commit is contained in:
parent
cac4c2f102
commit
67952f6840
7 changed files with 12 additions and 12 deletions
23
src/core/server/langid.rs
Normal file
23
src/core/server/langid.rs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
use crate::{Lazy, trace};
|
||||
use crate::config::SETTINGS;
|
||||
|
||||
use unic_langid::LanguageIdentifier;
|
||||
|
||||
/// Almacena el Identificador de Idioma Unicode ([Unicode Language Identifier]
|
||||
/// (https://unicode.org/reports/tr35/tr35.html#Unicode_language_identifier)) de
|
||||
/// la aplicación, obtenido de `SETTINGS.app.language`.
|
||||
pub static LANGID: Lazy<LanguageIdentifier> = Lazy::new(|| {
|
||||
match SETTINGS.app.language.parse() {
|
||||
Ok(language) => language,
|
||||
Err(_) => {
|
||||
trace::warn!(
|
||||
"Failed to parse language \"{}\". {}. {}. {}.",
|
||||
SETTINGS.app.language,
|
||||
"Unicode Language Identifier not recognized",
|
||||
"Using \"en-US\"",
|
||||
"Check the settings file",
|
||||
);
|
||||
"en-US".parse().unwrap()
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{Lazy, base, locale, trace};
|
||||
use crate::{Lazy, base, trace};
|
||||
use crate::config::SETTINGS;
|
||||
use crate::core::{Server, all, server};
|
||||
use crate::core::module::register_module;
|
||||
|
|
@ -32,11 +32,11 @@ pub fn run(bootstrap: Option<fn()>) -> Result<Server, std::io::Error> {
|
|||
);
|
||||
}
|
||||
|
||||
// Traza de seguimiento.
|
||||
Lazy::force(&trace::TRACING);
|
||||
// Inicia la traza de la aplicación.
|
||||
Lazy::force(&server::tracing::TRACING);
|
||||
|
||||
// Identificador de idioma.
|
||||
Lazy::force(&locale::LANGID);
|
||||
// Asigna identificador de idioma.
|
||||
Lazy::force(&server::langid::LANGID);
|
||||
|
||||
// Ejecuta la función de inicio de la aplicación.
|
||||
if bootstrap != None {
|
||||
|
|
|
|||
|
|
@ -2,5 +2,10 @@ pub use actix_web::{
|
|||
App, HttpRequest, HttpResponse, HttpServer, Responder, Result, http, web
|
||||
};
|
||||
|
||||
mod tracing;
|
||||
|
||||
mod langid;
|
||||
pub use langid::LANGID;
|
||||
|
||||
mod main;
|
||||
pub use main::run;
|
||||
|
|
|
|||
57
src/core/server/tracing.rs
Normal file
57
src/core/server/tracing.rs
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
use crate::Lazy;
|
||||
use crate::config::SETTINGS;
|
||||
|
||||
use tracing_appender::non_blocking::WorkerGuard;
|
||||
use tracing_subscriber::EnvFilter;
|
||||
|
||||
pub static TRACING: Lazy<WorkerGuard> = Lazy::new(|| {
|
||||
let env_filter = EnvFilter::try_new(&SETTINGS.log.tracing)
|
||||
.unwrap_or(EnvFilter::new("Info"));
|
||||
|
||||
let rolling = 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({
|
||||
let path = &SETTINGS.log.path;
|
||||
let prefix = &SETTINGS.log.prefix;
|
||||
match rolling.as_str() {
|
||||
"daily" => tracing_appender::rolling::daily(path, prefix),
|
||||
"hourly" => tracing_appender::rolling::hourly(path, prefix),
|
||||
"minutely" => tracing_appender::rolling::minutely(path, prefix),
|
||||
"endless" => tracing_appender::rolling::never(path, prefix),
|
||||
_ => {
|
||||
println!(
|
||||
"Rolling value \"{}\" not valid. {}. {}.",
|
||||
SETTINGS.log.rolling,
|
||||
"Using \"daily\"",
|
||||
"Check the settings file",
|
||||
);
|
||||
tracing_appender::rolling::daily(path, prefix)
|
||||
}
|
||||
}
|
||||
})
|
||||
};
|
||||
let subscriber = tracing_subscriber::fmt()
|
||||
.with_env_filter(env_filter)
|
||||
.with_writer(non_blocking)
|
||||
.with_ansi(rolling.as_str() == "stdout");
|
||||
match SETTINGS.log.format.to_lowercase().as_str() {
|
||||
"json" => subscriber.json().init(),
|
||||
"full" => subscriber.init(),
|
||||
"compact" => subscriber.compact().init(),
|
||||
"pretty" => subscriber.pretty().init(),
|
||||
_ => {
|
||||
println!(
|
||||
"Tracing format \"{}\" not valid. {}. {}.",
|
||||
SETTINGS.log.format,
|
||||
"Using \"Full\"",
|
||||
"Check the settings file",
|
||||
);
|
||||
subscriber.init();
|
||||
}
|
||||
}
|
||||
|
||||
guard
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue