summaryrefslogtreecommitdiff
path: root/browser/components/downloads/DownloadsLogger.jsm
diff options
context:
space:
mode:
authorMatt A. Tobin <email@mattatobin.com>2022-02-12 13:57:21 -0600
committerMatt A. Tobin <email@mattatobin.com>2022-02-12 13:57:21 -0600
commitba7d67bb0711c9066c71bd33e55d9a5d2f9b2cbf (patch)
treea5c0cfad71c17114c78d8a7d1f31112eb53896df /browser/components/downloads/DownloadsLogger.jsm
parentc054e324210895e7e2c5b3e84437cba43f201ec8 (diff)
downloadpalemoon-gre-ba7d67bb0711c9066c71bd33e55d9a5d2f9b2cbf.tar.gz
Lay down Pale Moon 30
Diffstat (limited to 'browser/components/downloads/DownloadsLogger.jsm')
-rw-r--r--browser/components/downloads/DownloadsLogger.jsm75
1 files changed, 75 insertions, 0 deletions
diff --git a/browser/components/downloads/DownloadsLogger.jsm b/browser/components/downloads/DownloadsLogger.jsm
new file mode 100644
index 000000000..845f1c91f
--- /dev/null
+++ b/browser/components/downloads/DownloadsLogger.jsm
@@ -0,0 +1,75 @@
+/* -*- Mode: js2; js2-basic-offset: 2; indent-tabs-mode: nil; -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/**
+ * The contents of this file were copied almost entirely from
+ * toolkit/identity/LogUtils.jsm. Until we've got a more generalized logging
+ * mechanism for toolkit, I think this is going to be how we roll.
+ */
+
+"use strict";
+
+this.EXPORTED_SYMBOLS = ["DownloadsLogger"];
+const PREF_DEBUG = "browser.download.debug";
+
+const Cu = Components.utils;
+const Ci = Components.interfaces;
+const Cc = Components.classes;
+const Cr = Components.results;
+
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+Cu.import("resource://gre/modules/Services.jsm");
+
+this.DownloadsLogger = {
+ _generateLogMessage: function(args) {
+ // create a string representation of a list of arbitrary things
+ let strings = [];
+
+ for (let arg of args) {
+ if (typeof arg === 'string') {
+ strings.push(arg);
+ } else if (arg === undefined) {
+ strings.push('undefined');
+ } else if (arg === null) {
+ strings.push('null');
+ } else {
+ try {
+ strings.push(JSON.stringify(arg, null, 2));
+ } catch(err) {
+ strings.push("<<something>>");
+ }
+ }
+ };
+ return 'Downloads: ' + strings.join(' ');
+ },
+
+ /**
+ * log() - utility function to print a list of arbitrary things
+ *
+ * Enable with about:config pref browser.download.debug
+ */
+ log: function(...args) {
+ let output = this._generateLogMessage(args);
+ dump(output + "\n");
+
+ // Additionally, make the output visible in the Error Console
+ Services.console.logStringMessage(output);
+ },
+
+ /**
+ * reportError() - report an error through component utils as well as
+ * our log function
+ */
+ reportError: function(...aArgs) {
+ // Report the error in the browser
+ let output = this._generateLogMessage(aArgs);
+ Cu.reportError(output);
+ dump("ERROR:" + output + "\n");
+ for (let frame = Components.stack.caller; frame; frame = frame.caller) {
+ dump("\t" + frame + "\n");
+ }
+ }
+
+};