Skip to content

Commit

Permalink
wip: remove all traces of 'log'
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioBenitez committed May 3, 2024
1 parent 5f9ff3f commit d01ca9c
Show file tree
Hide file tree
Showing 19 changed files with 84 additions and 327 deletions.
2 changes: 1 addition & 1 deletion benchmarks/src/routing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ fn generate_matching_requests<'c>(client: &'c Client, routes: &[Route]) -> Vec<L
fn client(routes: Vec<Route>) -> Client {
let config = Config {
profile: Config::RELEASE_PROFILE,
log_level: rocket::config::LogLevel::Off,
// log_level: rocket::config::LogLevel::Off,
cli_colors: config::CliColors::Never,
shutdown: config::ShutdownConfig {
ctrlc: false,
Expand Down
14 changes: 7 additions & 7 deletions contrib/db_pools/lib/src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ mod deadpool_old {
mod sqlx {
use sqlx::ConnectOptions;
use super::{Duration, Error, Config, Figment};
use rocket::config::LogLevel;
// use rocket::config::LogLevel;

type Options<D> = <<D as sqlx::Database>::Connection as sqlx::Connection>::Options;

Expand Down Expand Up @@ -302,12 +302,12 @@ mod sqlx {
specialize(&mut opts, &config);

opts = opts.disable_statement_logging();
if let Ok(level) = figment.extract_inner::<LogLevel>(rocket::Config::LOG_LEVEL) {
if !matches!(level, LogLevel::Normal | LogLevel::Off) {
opts = opts.log_statements(level.into())
.log_slow_statements(level.into(), Duration::default());
}
}
// if let Ok(level) = figment.extract_inner::<LogLevel>(rocket::Config::LOG_LEVEL) {
// if !matches!(level, LogLevel::Normal | LogLevel::Off) {
// opts = opts.log_statements(level.into())
// .log_slow_statements(level.into(), Duration::default());
// }
// }

sqlx::pool::PoolOptions::new()
.max_connections(config.max_connections as u32)
Expand Down
2 changes: 1 addition & 1 deletion contrib/dyn_templates/src/fairing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl Fairing for TemplateFairing {
}

async fn on_liftoff(&self, rocket: &Rocket<Orbit>) {
use rocket::{figment::Source, log::PaintExt, yansi::Paint};
use rocket::{figment::Source, yansi::Paint};

let cm = rocket.state::<ContextManager>()
.expect("Template ContextManager registered in on_ignite");
Expand Down
28 changes: 14 additions & 14 deletions core/codegen/src/attribute/route/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fn query_decls(route: &Route) -> Option<TokenStream> {
}

define_spanned_export!(Span::call_site() =>
__req, __data, _log, _form, Outcome, _Ok, _Err, _Some, _None, Status
__req, __data, _form, Outcome, _Ok, _Err, _Some, _None, Status
);

// Record all of the static parameters for later filtering.
Expand Down Expand Up @@ -105,8 +105,8 @@ fn query_decls(route: &Route) -> Option<TokenStream> {
)*

if !__e.is_empty() {
#_log::warn_!("Query string failed to match route declaration.");
for _err in __e { #_log::warn_!("{}", _err); }
::rocket::warn_!("Query string failed to match route declaration.");
for _err in __e { ::rocket::warn_!("{}", _err); }
return #Outcome::Forward((#__data, #Status::UnprocessableEntity));
}

Expand All @@ -118,18 +118,18 @@ fn query_decls(route: &Route) -> Option<TokenStream> {
fn request_guard_decl(guard: &Guard) -> TokenStream {
let (ident, ty) = (guard.fn_ident.rocketized(), &guard.ty);
define_spanned_export!(ty.span() =>
__req, __data, _request, _log, FromRequest, Outcome
__req, __data, _request, FromRequest, Outcome
);

quote_spanned! { ty.span() =>
let #ident: #ty = match <#ty as #FromRequest>::from_request(#__req).await {
#Outcome::Success(__v) => __v,
#Outcome::Forward(__e) => {
#_log::warn_!("Request guard `{}` is forwarding.", stringify!(#ty));
::rocket::warn_!("Request guard `{}` is forwarding.", stringify!(#ty));
return #Outcome::Forward((#__data, __e));
},
#Outcome::Error((__c, __e)) => {
#_log::warn_!("Request guard `{}` failed: {:?}.", stringify!(#ty), __e);
::rocket::warn_!("Request guard `{}` failed: {:?}.", stringify!(#ty), __e);
return #Outcome::Error(__c);
}
};
Expand All @@ -139,13 +139,13 @@ fn request_guard_decl(guard: &Guard) -> TokenStream {
fn param_guard_decl(guard: &Guard) -> TokenStream {
let (i, name, ty) = (guard.index, &guard.name, &guard.ty);
define_spanned_export!(ty.span() =>
__req, __data, _log, _None, _Some, _Ok, _Err,
__req, __data, _None, _Some, _Ok, _Err,
Outcome, FromSegments, FromParam, Status
);

// Returned when a dynamic parameter fails to parse.
let parse_error = quote!({
#_log::warn_!("Parameter guard `{}: {}` is forwarding: {:?}.",
::rocket::warn_!("Parameter guard `{}: {}` is forwarding: {:?}.",
#name, stringify!(#ty), __error);

#Outcome::Forward((#__data, #Status::UnprocessableEntity))
Expand All @@ -161,9 +161,9 @@ fn param_guard_decl(guard: &Guard) -> TokenStream {
#_Err(__error) => return #parse_error,
},
#_None => {
#_log::error_!("Internal invariant broken: dyn param {} not found.", #i);
#_log::error_!("Please report this to the Rocket issue tracker.");
#_log::error_!("https://github.com/rwf2/Rocket/issues");
::rocket::error_!("Internal invariant broken: dyn param {} not found.", #i);
::rocket::error_!("Please report this to the Rocket issue tracker.");
::rocket::error_!("https://github.com/rwf2/Rocket/issues");
return #Outcome::Forward((#__data, #Status::InternalServerError));
}
}
Expand All @@ -182,17 +182,17 @@ fn param_guard_decl(guard: &Guard) -> TokenStream {

fn data_guard_decl(guard: &Guard) -> TokenStream {
let (ident, ty) = (guard.fn_ident.rocketized(), &guard.ty);
define_spanned_export!(ty.span() => _log, __req, __data, FromData, Outcome);
define_spanned_export!(ty.span() => __req, __data, FromData, Outcome);

quote_spanned! { ty.span() =>
let #ident: #ty = match <#ty as #FromData>::from_data(#__req, #__data).await {
#Outcome::Success(__d) => __d,
#Outcome::Forward((__d, __e)) => {
#_log::warn_!("Data guard `{}` is forwarding.", stringify!(#ty));
::rocket::warn_!("Data guard `{}` is forwarding.", stringify!(#ty));
return #Outcome::Forward((__d, __e));
}
#Outcome::Error((__c, __e)) => {
#_log::warn_!("Data guard `{}` failed: {:?}.", stringify!(#ty), __e);
::rocket::warn_!("Data guard `{}` failed: {:?}.", stringify!(#ty), __e);
return #Outcome::Error(__c);
}
};
Expand Down
1 change: 0 additions & 1 deletion core/codegen/src/exports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ define_exported_paths! {
_route => ::rocket::route,
_catcher => ::rocket::catcher,
_sentinel => ::rocket::sentinel,
_log => ::rocket::log,
_form => ::rocket::form::prelude,
_http => ::rocket::http,
_uri => ::rocket::http::uri,
Expand Down
23 changes: 9 additions & 14 deletions core/lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ x509-parser = { version = "0.16", optional = true }
http = "1"
bytes = "1.4"
hyper = { version = "1.1", default-features = false, features = ["http1", "server"] }
hyper-util = { version = "0.1.3", default-features = false, features = ["http1", "server", "tokio"] }

# Non-optional, core dependencies from here on out.
yansi = { version = "1.0.1", features = ["detect-tty"] }
log = { version = "0.4", features = ["std"] }
num_cpus = "1.0"
time = { version = "0.3", features = ["macros", "parsing"] }
memchr = "2" # TODO: Use pear instead.
Expand All @@ -83,10 +83,14 @@ cookie = { version = "0.18", features = ["percent-encode"] }
futures = { version = "0.3.30", default-features = false, features = ["std"] }
state = "0.6"

[dependencies.hyper-util]
version = "0.1.3"
default-features = false
features = ["http1", "server", "tokio"]
[dependencies.rocket_codegen]
version = "0.6.0-dev"
path = "../codegen"

[dependencies.rocket_http]
version = "0.6.0-dev"
path = "../http"
features = ["serde"]

[dependencies.tokio]
version = "1.35.1"
Expand All @@ -97,15 +101,6 @@ version = "0.7"
default-features = false
features = ["io"]

[dependencies.rocket_codegen]
version = "0.6.0-dev"
path = "../codegen"

[dependencies.rocket_http]
version = "0.6.0-dev"
path = "../http"
features = ["serde"]

[dependencies.rustls]
version = "0.23"
default-features = false
Expand Down
2 changes: 1 addition & 1 deletion core/lib/fuzz/targets/collision-matching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ type TestData<'a> = (
fn fuzz((route_a, route_b, req): TestData<'_>) {
let rocket = rocket::custom(rocket::Config {
workers: 2,
log_level: rocket::log::LogLevel::Off,
// log_level: rocket::log::LogLevel::Off,
cli_colors: rocket::config::CliColors::Never,
..rocket::Config::debug_default()
});
Expand Down
21 changes: 11 additions & 10 deletions core/lib/src/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ use figment::value::{Map, Dict, magic::RelativePathBuf};
use serde::{Deserialize, Serialize};
use yansi::{Paint, Style, Color::Primary};

use crate::log::PaintExt;
use crate::config::{LogLevel, ShutdownConfig, Ident, CliColors};
// use crate::log::PaintExt;
// use crate::config::{LogLevel, ShutdownConfig, Ident, CliColors};
use crate::config::{ShutdownConfig, Ident, CliColors};
use crate::request::{self, Request, FromRequest};
use crate::http::uncased::Uncased;
use crate::data::Limits;
Expand Down Expand Up @@ -122,8 +123,8 @@ pub struct Config {
pub secret_key: SecretKey,
/// Graceful shutdown configuration. **(default: [`ShutdownConfig::default()`])**
pub shutdown: ShutdownConfig,
/// Max level to log. **(default: _debug_ `normal` / _release_ `critical`)**
pub log_level: LogLevel,
// /// Max level to log. **(default: _debug_ `normal` / _release_ `critical`)**
// pub log_level: LogLevel,
/// Whether to use colors and emoji when logging. **(default:
/// [`CliColors::Auto`])**
pub cli_colors: CliColors,
Expand Down Expand Up @@ -201,7 +202,7 @@ impl Config {
#[cfg(feature = "secrets")]
secret_key: SecretKey::zero(),
shutdown: ShutdownConfig::default(),
log_level: LogLevel::Normal,
// log_level: LogLevel::Normal,
cli_colors: CliColors::Auto,
__non_exhaustive: (),
}
Expand All @@ -225,7 +226,7 @@ impl Config {
pub fn release_default() -> Config {
Config {
profile: Self::RELEASE_PROFILE,
log_level: LogLevel::Critical,
// log_level: LogLevel::Critical,
..Config::debug_default()
}
}
Expand Down Expand Up @@ -327,9 +328,9 @@ impl Config {

#[inline]
pub(crate) fn trace_print(&self, figment: &Figment) {
if self.log_level != LogLevel::Debug {
return;
}
// if self.log_level != LogLevel::Debug {
// return;
// }

trace!("-- configuration trace information --");
for param in Self::PARAMETERS {
Expand Down Expand Up @@ -536,7 +537,7 @@ pub fn bail_with_config_error<T>(error: figment::Error) -> T {
pub fn pretty_print_error(error: figment::Error) {
use figment::error::{Kind, OneOf};

crate::log::init_default();
// crate::log::init_default();
error!("Failed to extract valid configuration.");
for e in error {
fn w<T>(v: T) -> yansi::Painted<T> { Paint::new(v).primary() }
Expand Down
2 changes: 1 addition & 1 deletion core/lib/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ pub use ident::Ident;
pub use config::Config;
pub use cli_colors::CliColors;

pub use crate::log::LogLevel;
// pub use crate::log::LogLevel;
pub use crate::shutdown::ShutdownConfig;

#[cfg(feature = "tls")]
Expand Down
8 changes: 4 additions & 4 deletions core/lib/src/config/tests.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use figment::{Figment, Profile};
use pretty_assertions::assert_eq;

use crate::log::LogLevel;
// use crate::log::LogLevel;
use crate::data::{Limits, ToByteUnit};
use crate::config::{Config, CliColors};

Expand Down Expand Up @@ -65,7 +65,7 @@ fn test_toml_file() {
workers: 20,
ident: ident!("Something Cool"),
keep_alive: 10,
log_level: LogLevel::Off,
// log_level: LogLevel::Off,
cli_colors: CliColors::Never,
..Config::default()
});
Expand All @@ -84,7 +84,7 @@ fn test_toml_file() {
workers: 20,
ident: ident!("Something Else Cool"),
keep_alive: 10,
log_level: LogLevel::Off,
// log_level: LogLevel::Off,
cli_colors: CliColors::Never,
..Config::default()
});
Expand All @@ -102,7 +102,7 @@ fn test_toml_file() {
assert_eq!(config, Config {
workers: 20,
keep_alive: 10,
log_level: LogLevel::Off,
// log_level: LogLevel::Off,
cli_colors: CliColors::Never,
..Config::default()
});
Expand Down
2 changes: 1 addition & 1 deletion core/lib/src/fairing/fairings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::collections::HashSet;

use crate::{Rocket, Request, Response, Data, Build, Orbit};
use crate::fairing::{Fairing, Info, Kind};
use crate::log::PaintExt;
// use crate::log::PaintExt;

use yansi::Paint;

Expand Down
2 changes: 1 addition & 1 deletion core/lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ pub use time;

#[doc(hidden)]
#[macro_use]
pub mod log;
pub mod trace;
#[macro_use]
pub mod outcome;
#[macro_use]
Expand Down
2 changes: 1 addition & 1 deletion core/lib/src/local/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ macro_rules! pub_client_impl {
use crate::config;

let figment = rocket.figment().clone()
.merge((config::Config::LOG_LEVEL, config::LogLevel::Debug))
// .merge((config::Config::LOG_LEVEL, config::LogLevel::Debug))
.select(config::Config::DEBUG_PROFILE);

Self::tracked(rocket.reconfigure(figment)) $(.$suffix)?
Expand Down
Loading

0 comments on commit d01ca9c

Please sign in to comment.