From c0163d2d608903b8106543061741b9119754cbb4 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Tue, 3 Feb 2015 18:42:30 -0800 Subject: [PATCH] [Logging] Wire in log levels Wire in log levels to allow specifying as a query string parameter; defaults to logging only warnings and above, for WTD-793. --- platform/framework/src/LogLevel.js | 6 ++++-- platform/framework/src/Main.js | 13 +++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/platform/framework/src/LogLevel.js b/platform/framework/src/LogLevel.js index bbcd6bcb1d..d834ba83f7 100644 --- a/platform/framework/src/LogLevel.js +++ b/platform/framework/src/LogLevel.js @@ -43,7 +43,6 @@ define( log[m] = NOOP; } }); - return log; } // Default to 'warn' level if unspecified @@ -67,7 +66,10 @@ define( configure: function (app, $log) { decorate($log); app.config(function ($provide) { - $provide.decorator('$log', decorate); + $provide.decorator('$log', function ($delegate) { + decorate($delegate); + return $delegate; + }); }); } }; diff --git a/platform/framework/src/Main.js b/platform/framework/src/Main.js index d0c7978379..27bad9fb68 100644 --- a/platform/framework/src/Main.js +++ b/platform/framework/src/Main.js @@ -19,6 +19,7 @@ define( '../lib/angular-route.min', './Constants', './FrameworkInitializer', + './LogLevel', './load/BundleLoader', './resolve/ImplementationLoader', './resolve/ExtensionResolver', @@ -36,6 +37,7 @@ define( angularRoute, Constants, FrameworkInitializer, + LogLevel, BundleLoader, ImplementationLoader, ExtensionResolver, @@ -52,6 +54,12 @@ define( // services, which are useful to the framework layer. var injector = angular.injector(['ng']); + // Look up log level from query string + function logLevel() { + var match = /[?&]log=([a-z]+)/.exec(window.location.search); + return match ? match[1] : ""; + } + // Polyfill Promise, in case browser does not natively provide Promise window.Promise = window.Promise || es6promise.Promise; @@ -86,6 +94,11 @@ define( bootstrapper ); + // Apply logging levels; this must be done now, before the + // first log statement. + new LogLevel(logLevel()).configure(app, $log); + + // Initialize the application $log.info("Initializing application."); initializer.runApplication(Constants.BUNDLE_LISTING_FILE); }