From 7cf3cb6bc66935819d61c18f2d385263cf825aac Mon Sep 17 00:00:00 2001 From: Sergio Benitez Date: Thu, 22 Dec 2016 00:53:43 -0800 Subject: [PATCH] Only enable codegen logging with env var. --- codegen/src/decorators/route.rs | 3 --- codegen/src/lib.rs | 8 ++++++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/codegen/src/decorators/route.rs b/codegen/src/decorators/route.rs index 814ff4e1..e43a173a 100644 --- a/codegen/src/decorators/route.rs +++ b/codegen/src/decorators/route.rs @@ -218,9 +218,6 @@ fn generic_route_decorator(known_method: Option>, meta_item: &MetaItem, annotated: &Annotatable, push: &mut FnMut(Annotatable)) { - // Initialize the logger. - ::rocket::logger::init(::rocket::LoggingLevel::Debug); - // Parse the route and generate the code to create the form and param vars. let route = RouteParams::from(ecx, sp, known_method, meta_item, annotated); debug!("Route params: {:?}", route); diff --git a/codegen/src/lib.rs b/codegen/src/lib.rs index 5b5c7e74..9d19a4f0 100644 --- a/codegen/src/lib.rs +++ b/codegen/src/lib.rs @@ -15,10 +15,13 @@ mod parser; mod macros; mod decorators; +use std::env; use rustc_plugin::Registry; use syntax::ext::base::SyntaxExtension; use syntax::symbol::Symbol; +const DEBUG_ENV_VAR: &'static str = "ROCKET_CODEGEN_DEBUG"; + const PARAM_PREFIX: &'static str = "rocket_param_"; const ROUTE_STRUCT_PREFIX: &'static str = "static_rocket_route_info_for_"; const CATCH_STRUCT_PREFIX: &'static str = "static_rocket_catch_info_for_"; @@ -35,6 +38,11 @@ macro_rules! register_decorators { #[plugin_registrar] pub fn plugin_registrar(reg: &mut Registry) { + // Enable logging early if the DEBUG_ENV_VAR is set. + if env::var(DEBUG_ENV_VAR).is_ok() { + ::rocket::logger::init(::rocket::LoggingLevel::Debug); + } + reg.register_macro("routes", macros::routes); reg.register_macro("errors", macros::errors);