mirror of https://github.com/rwf2/Rocket.git
Initialize logger earlier to log more errors.
Specifically, errors that occurred _before_ ignite time went unlogged as no logger was initialized. This commit rectifies the situation.
This commit is contained in:
parent
f8efa64ae2
commit
0cd8bd2313
|
@ -441,10 +441,7 @@ impl<'r> FromRequest<'r> for &'r Config {
|
|||
pub fn pretty_print_error(error: figment::Error) {
|
||||
use figment::error::{Kind, OneOf};
|
||||
|
||||
let mut config = Config::debug_default();
|
||||
config.log_level = LogLevel::Debug;
|
||||
crate::log::init(&config);
|
||||
|
||||
crate::log::init_default();
|
||||
error!("Rocket configuration extraction from provider failed.");
|
||||
for e in error {
|
||||
fn w<T: std::fmt::Display>(v: T) -> Paint<T> { Paint::white(v) }
|
||||
|
|
|
@ -107,6 +107,7 @@ impl FileServer {
|
|||
/// rocket::build().mount("/static", FileServer::from("/www/public").rank(30))
|
||||
/// }
|
||||
/// ```
|
||||
#[track_caller]
|
||||
pub fn from<P: AsRef<Path>>(path: P) -> Self {
|
||||
FileServer::new(path, Options::default())
|
||||
}
|
||||
|
@ -138,14 +139,16 @@ impl FileServer {
|
|||
/// .mount("/pub", FileServer::new("/www/public", options).rank(-1))
|
||||
/// }
|
||||
/// ```
|
||||
#[track_caller]
|
||||
pub fn new<P: AsRef<Path>>(path: P, options: Options) -> Self {
|
||||
use crate::yansi::Paint;
|
||||
|
||||
let path = path.as_ref();
|
||||
if !path.is_dir() {
|
||||
error!("`FileServer` supplied with invalid path");
|
||||
info_!("'{}' is not a directory", Paint::white(path.display()));
|
||||
panic!("refusing to continue due to invalid static files path");
|
||||
let path = path.display();
|
||||
error!("FileServer path '{}' is not a directory.", Paint::white(path));
|
||||
warn_!("Aborting early to prevent inevitable handler failure.");
|
||||
panic!("bad FileServer path: refusing to continue");
|
||||
}
|
||||
|
||||
FileServer { root: path.into(), options, rank: Self::DEFAULT_RANK }
|
||||
|
|
|
@ -129,6 +129,10 @@ impl log::Log for RocketLogger {
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) fn init_default() -> bool {
|
||||
crate::log::init(&crate::Config::debug_default())
|
||||
}
|
||||
|
||||
pub(crate) fn init(config: &crate::Config) -> bool {
|
||||
static HAS_ROCKET_LOGGER: AtomicBool = AtomicBool::new(false);
|
||||
|
||||
|
|
|
@ -151,6 +151,10 @@ impl Rocket<Build> {
|
|||
/// }
|
||||
/// ```
|
||||
pub fn custom<T: Provider>(provider: T) -> Self {
|
||||
// We initialize the logger here so that logging from fairings and so on
|
||||
// are visible; we use the final config to set a max log-level in ignite
|
||||
crate::log::init_default();
|
||||
|
||||
let rocket: Rocket<Build> = Rocket(Building {
|
||||
figment: Figment::from(provider),
|
||||
..Default::default()
|
||||
|
@ -466,9 +470,6 @@ impl Rocket<Build> {
|
|||
/// }
|
||||
/// ```
|
||||
pub async fn ignite(mut self) -> Result<Rocket<Ignite>, Error> {
|
||||
// We initialize the logger here so that logging from fairings are
|
||||
// visible but change the max-log-level when we have a final config.
|
||||
crate::log::init(&Config::debug_default());
|
||||
self = Fairings::handle_ignite(self).await;
|
||||
self.fairings.audit().map_err(|f| ErrorKind::FailedFairings(f.to_vec()))?;
|
||||
|
||||
|
|
Loading…
Reference in New Issue