Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

Updated logging to directly map functions to console object in order to get the correct files and line numbers in Firefox log

Mike McGanna5f5a2c478b0
diff --git a/js/Logging.js b/js/Logging.js
index 1aae330c8..2a3488d89 100644
--- a/js/Logging.js
+++ b/js/Logging.js
@@ -46,8 +46,19 @@
(function(ns) {
var debugging = {};
- var debuggingAll = false;
-
+ var loggers = {};
+
+ ns.getLogger = function(namespace) {
+ var logger = null;
+ if ( namespace in loggers ) {
+ logger = loggers[namespace];
+ } else {
+ logger = Logger();
+ loggers[namespace] = logger;
+ }
+ return logger;
+ }
+
/**
* Function: debug
* Enables debug logging.
@@ -58,10 +69,7 @@
* for all <Loggers>.
*/
ns.debug = function(namespace) {
- if ( namespace === undefined ) {
- debuggingAll = true;
- }
- debugging[namespace] = true;
+ ns.getLogger(namespace).setDebugEnabled(true);
};
/**
@@ -74,17 +82,11 @@
* for all <Loggers> except for those explicitly enabled.
*/
ns.undebug = function(namespace) {
- if ( namespace === undefined ) {
- debuggingAll = false;
- } else {
- if ( namespace in debugging ) {
- delete debugging[namespace];
- }
- }
+ ns.getLogger(namespace).setDebugEnabled(false);
};
/**
- * Class: Logging.Logger
+ * Class: Logging.getLogger
* Sample logger
*
* Constructor: Logger
@@ -93,7 +95,7 @@
* Parameters:
* namespace - The name given to this logger.
*/
- ns.Logger = function(namespace) {
+ var Logger = function() {
var self = {};
@@ -105,12 +107,8 @@
* Parameters:
* message - The message to print to the console.
*/
- self.message = function(message) {
- if ( console ) {
- console.log(message);
- }
- };
-
+ self.message = ( console && console.log ) || function() {};
+
/**
* Method: error
* Prints an error message to the console. Uses console.error if
@@ -120,15 +118,7 @@
* Parameters:
* message - The message to print to the console.
*/
- self.error = function(message) {
- if ( console ) {
- if ( console.error ) {
- console.error(message);
- } else {
- console.log(message);
- }
- }
- };
+ self.error = console.error || self.mesesage;
/**
* Method: warn
@@ -139,15 +129,8 @@
* Parameters:
* message - The message to print to the console.
*/
- self.warn = function(message) {
- if ( console ) {
- if ( console.warn ) {
- console.warn(message);
- } else {
- console.log(message);
- }
- }
- };
+ self.warn = console.warn || self.message;
+
/**
* Method: info
@@ -158,26 +141,14 @@
* Parameters:
* message - The message to print to the console.
*/
- self.info = function(message) {
- if ( console ) {
- if ( console.info ) {
- console.info(message);
- } else {
- console.log(message);
- }
- }
- };
+ self.info = console.info || self.message;
/**
* Method: trace
* Prints a stack trace to the console. If console.trace does not
* exist, this method does nothing.
*/
- self.trace = function() {
- if ( console && console.trace ) {
- console.trace();
- }
- };
+ self.trace = console.trace || function() {}
/**
* Method: debug
@@ -189,14 +160,17 @@
* Parameters:
* message - The message to print to the console.
*/
- self.debug = function(message) {
- if ( debuggingAll ) {
- self.message(message);
- } else if ( namespace !== undefined && namespace in debugging ) {
- self.message(message);
+ self.debug = function() {};
+
+ self.setDebugEnabled = function(enabled) {
+ if ( enabled ) {
+ self.debug = self.message;
+ } else {
+ self.debug = function() {};
}
- }
-
+ };
+
+
return self;
};
diff --git a/js/Worldview.js b/js/Worldview.js
index 20d95495d..f091191e2 100644
--- a/js/Worldview.js
+++ b/js/Worldview.js
@@ -3,7 +3,7 @@
*/
(function(ns) {
- var log = Logging.Logger("Worldview");
+ var log = Logging.getLogger("Worldview");
/**
* Constant: NAME
diff --git a/js/Worldview/Map/CanvasTile.js b/js/Worldview/Map/CanvasTile.js
index 4f68da3ce..fea9278c6 100644
--- a/js/Worldview/Map/CanvasTile.js
+++ b/js/Worldview/Map/CanvasTile.js
@@ -56,7 +56,7 @@ Worldview.Map.CanvasTile = OpenLayers.Class(OpenLayers.Tile.Image, {
graphics: null,
grpahicsOriginal: null,
latestJobId: null,
- log: Logging.Logger("Worldview.Map.CanvasTile"),
+ log: Logging.getLogger("Worldview.Map.CanvasTile"),
initialize: function(layer, position, bounds, url, size, options) {
// This is required or the browser will throw security exceptions
diff --git a/js/Worldview/Map/ProductMap.js b/js/Worldview/Map/ProductMap.js
index 77b0c9fbb..a42372735 100644
--- a/js/Worldview/Map/ProductMap.js
+++ b/js/Worldview/Map/ProductMap.js
@@ -29,7 +29,7 @@ Worldview.namespace("Map");
*/
Worldview.Map.ProductMap = function(containerId, mapConfig, component) {
- var log = Logging.Logger("Worldview.Map");
+ var log = Logging.getLogger("Worldview.Map");
var self = {};
// Map objects, one for each supported projection
diff --git a/js/Worldview/Scheduler.js b/js/Worldview/Scheduler.js
index 0cf065393..deffb42fe 100644
--- a/js/Worldview/Scheduler.js
+++ b/js/Worldview/Scheduler.js
@@ -1,7 +1,7 @@
Worldview.Scheduler = function(workerScript, maxJobs) {
- var log = Logging.Logger("Worldview.Scheduler");
+ var log = Logging.getLogger("Worldview.Scheduler");
var self = {};
var workers = [];
var queue = [];
diff --git a/js/Worldview/Support.js b/js/Worldview/Support.js
index 3561975ad..e8caa6b01 100644
--- a/js/Worldview/Support.js
+++ b/js/Worldview/Support.js
@@ -4,7 +4,7 @@ Worldview.namespace("Support");
ns.WEB_WORKERS = false;
- var log = Logging.Logger();
+ var log = Logging.getLogger();
/*
* jQuery version 1.6 causes thousands of warnings to be emitted to the
diff --git a/js/Worldview/Widget/Map.js b/js/Worldview/Widget/Map.js
index ee8f1a5c8..6fa6f9ef5 100644
--- a/js/Worldview/Widget/Map.js
+++ b/js/Worldview/Widget/Map.js
@@ -28,7 +28,7 @@ Worldview.namespace("Widget");
Worldview.Widget.Map = function(containerId, config) {
var self = {};
- var log = Logging.Logger("Worldview.Map");
+ var log = Logging.getLogger("Worldview.Map");
/**
* Property: productMap
diff --git a/js/Worldview/Widget/PaletteManager.js b/js/Worldview/Widget/PaletteManager.js
index 2c41d0d78..4c350413a 100644
--- a/js/Worldview/Widget/PaletteManager.js
+++ b/js/Worldview/Widget/PaletteManager.js
@@ -14,7 +14,7 @@ Worldview.namespace("Widget");
Worldview.Widget.PaletteManager = function(containerId, config) {
var self = {};
- var log = Logging.Logger("Worldview.PaletteManager");
+ var log = Logging.getLogger("Worldview.PaletteManager");
var value = "";
var activePalettes = {};
diff --git a/js/Worldview/Widget/WorldviewMap.js b/js/Worldview/Widget/WorldviewMap.js
index c2e3fbac4..c6a57752f 100644
--- a/js/Worldview/Widget/WorldviewMap.js
+++ b/js/Worldview/Widget/WorldviewMap.js
@@ -34,7 +34,7 @@ Worldview.Widget.WorldviewMap = function(containerId, config) {
var self = ns.Map(containerId, config);
- var log = Logging.Logger("Worldview.Map");
+ var log = Logging.getLogger("Worldview.Map");
var lastState = {};
var last = null;
diff --git a/js/bank.js b/js/bank.js
index 8dd947ecf..f09eb15da 100644
--- a/js/bank.js
+++ b/js/bank.js
@@ -19,7 +19,7 @@ SOTE.widget.Bank.prototype = new SOTE.widget.Component;
*
*/
SOTE.widget.Bank = function(containerId, config){
- this.log = Logging.Logger("Worldview.Widget.Bank");
+ this.log = Logging.getLogger("Worldview.Widget.Bank");
this.VALID_PROJECTIONS = ["geographic", "artcic", "antarctic"];
//Get the ID of the container element
diff --git a/js/dateSpan.js b/js/dateSpan.js
index ab8a8e016..7c5947595 100644
--- a/js/dateSpan.js
+++ b/js/dateSpan.js
@@ -26,7 +26,7 @@ SOTE.namespace("SOTE.widget.DateSpan");
*
*/
SOTE.widget.DateSpan = function(containerId, config){
- this.log = Logging.Logger("Worldview.Widget.DateSpan");
+ this.log = Logging.getLogger("Worldview.Widget.DateSpan");
this.SLIDER_WIDTH = 1000;
this.DAY_IN_MS = 24*60*60*1000;
this.sliders = new Object();
diff --git a/js/main.js b/js/main.js
index 44be75197..3fad8fd36 100644
--- a/js/main.js
+++ b/js/main.js
@@ -1,6 +1,6 @@
$(function() {// Initialize "static" vars
- var log = Logging.Logger();
+ var log = Logging.getLogger();
var selector;
var entryPoint = function() {
diff --git a/js/switch.js b/js/switch.js
index e93d10789..e32c0c2b7 100644
--- a/js/switch.js
+++ b/js/switch.js
@@ -19,7 +19,7 @@ SOTE.widget.Switch.prototype = new SOTE.widget.Component;
*
*/
SOTE.widget.Switch = function(containerId, config){
- this.log = Logging.Logger("Worldview.Widget.Switch");
+ this.log = Logging.getLogger("Worldview.Widget.Switch");
this.VALID_PROJECTIONS = ["geographic", "arctic", "antarctic"];
//Get the ID of the container element
diff --git a/test/testLogging.js b/test/testLogging.js
index f25353b07..074210367 100644
--- a/test/testLogging.js
+++ b/test/testLogging.js
@@ -28,7 +28,7 @@ TestCase("Logging.standard", TestSuite.Tests({
testMessage: function() {
var mockLog = mockFunction();
patcher.apply("console.log", mockLog);
- Logging.Logger().message("log");
+ Logging.getLogger().message("log");
verify(mockLog)("log");
},
@@ -36,7 +36,7 @@ TestCase("Logging.standard", TestSuite.Tests({
testError: function() {
var mockError = mockFunction();
patcher.apply("console.error", mockError);
- Logging.Logger().error("error");
+ Logging.getLogger().error("error");
verify(mockError)("error");
},
@@ -44,7 +44,7 @@ TestCase("Logging.standard", TestSuite.Tests({
testInfo: function() {
var mockInfo = mockFunction();
patcher.apply("console.info", mockInfo);
- Logging.Logger().info("info");
+ Logging.getLogger().info("info");
verify(mockInfo)("info");
},
@@ -52,7 +52,7 @@ TestCase("Logging.standard", TestSuite.Tests({
testWarn: function() {
var mockWarn = mockFunction();
patcher.apply("console.warn", mockWarn);
- Logging.Logger().warn("warn");
+ Logging.getLogger().warn("warn");
verify(mockWarn)("warn");
},
@@ -60,7 +60,7 @@ TestCase("Logging.standard", TestSuite.Tests({
testTrace: function() {
var mockTrace = mockFunction();
patcher.apply("console.trace", mockTrace);
- Logging.Logger().trace();
+ Logging.getLogger().trace();
verify(mockTrace)();
},
@@ -68,7 +68,7 @@ TestCase("Logging.standard", TestSuite.Tests({
testDebugDisabled: function() {
var mockLog = mockFunction();
patcher.apply("console.log", mockLog);
- Logging.Logger("foo").debug("foo");
+ Logging.getLogger("foo").debug("foo");
verifyZeroInteractions(mockLog);
},
@@ -77,7 +77,7 @@ TestCase("Logging.standard", TestSuite.Tests({
var mockLog = mockFunction();
patcher.apply("console.log", mockLog);
Logging.debug("foo");
- Logging.Logger("foo").debug("foo");
+ Logging.getLogger("foo").debug("foo");
verify(mockLog)("foo");
},
@@ -85,7 +85,7 @@ TestCase("Logging.standard", TestSuite.Tests({
testDebugDisabledNoNamespace: function() {
var mockLog = mockFunction();
patcher.apply("console.log", mockLog);
- Logging.Logger().debug("foo");
+ Logging.getLogger().debug("foo");
verifyZeroInteractions(mockLog);
},
@@ -94,7 +94,7 @@ TestCase("Logging.standard", TestSuite.Tests({
var mockLog = mockFunction();
patcher.apply("console.log", mockLog);
Logging.debug();
- Logging.Logger().debug("foo");
+ Logging.getLogger().debug("foo");
verify(mockLog)("foo");
},
@@ -103,7 +103,7 @@ TestCase("Logging.standard", TestSuite.Tests({
var mockLog = mockFunction();
patcher.apply("console.log", mockLog);
Logging.debug();
- Logging.Logger("foo").debug("foo");
+ Logging.getLogger("foo").debug("foo");
verify(mockLog)("foo");
}
@@ -124,11 +124,11 @@ TestCase("Logging.noConsole", TestSuite.Tests({
// Test that no errors are thrown when console is undefined
testAll: function() {
- Logging.Logger().error("foo");
- Logging.Logger().message("foo");
- Logging.Logger().info("foo");
- Logging.Logger().warn("foo");
- Logging.Logger().trace("foo");
+ Logging.getLogger().error("foo");
+ Logging.getLogger().message("foo");
+ Logging.getLogger().info("foo");
+ Logging.getLogger().warn("foo");
+ Logging.getLogger().trace("foo");
}
}));
@@ -154,25 +154,25 @@ TestCase("Logging.onlyLog", TestSuite.Tests({
// Check that log is called when error is not defined
testError: function() {
- Logging.Logger().error("foo");
+ Logging.getLogger().error("foo");
verify(mockLog)("foo");
},
// Check that log is called when info is not defined
testInfo: function() {
- Logging.Logger().info("foo");
+ Logging.getLogger().info("foo");
verify(mockLog)("foo");
},
// Check that warn is called when error is not defined
testWarn: function() {
- Logging.Logger().warn("foo");
+ Logging.getLogger().warn("foo");
verify(mockLog)("foo");
},
// Check that there is no error when trace is not defined
testTrace: function() {
- Logging.Logger().trace();
+ Logging.getLogger().trace();
}
}));