Only enable codegen logging with env var.

This commit is contained in:
Sergio Benitez 2016-12-22 00:53:43 -08:00
parent 07b5c3de2e
commit 7cf3cb6bc6
2 changed files with 8 additions and 3 deletions

View File

@ -218,9 +218,6 @@ fn generic_route_decorator(known_method: Option<Spanned<Method>>,
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);

View File

@ -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);