Closed Bug 940037 Opened 11 years ago Closed 2 years ago

Provide a better Components.utils.reportError

Categories

(Toolkit :: General, defect)

defect

Tracking

()

RESOLVED WORKSFORME

People

(Reporter: Yoric, Unassigned)

References

Details

We generally use Components.utils.reportError to provide one-liner reporting for exceptions. Unfortunately, this loses most of the interesting information, in particular the stack. try { // ... } catch (ex) { logError("Something failed", ex); // Displays "Something failed", a time stamp, the full stack of |ex| if available, the error message of |ex|, the file name, line number. } Ideally, this should be available on workers, too, but this can wait for a followup bug.
Irving, gps, gozala, I seem to remember that you all have logging libraries on mozilla-central (perhaps it's the same ones, I haven't checked). Would they do the trick?
Flags: needinfo?(rFobic)
Flags: needinfo?(irving)
Flags: needinfo?(gps)
toolkit/modules/Log.jsm. It has support for "structured" messages. These are messages that are represented by a JS value instead of a string and contain a custom formatting function that can convert said value into a string for human display. Or they can convert it to JSON for machine consumption. You get the idea. I'd still like to add a "logging service" that handles things like hooking Log.jsm up to preferences so you can e.g. easily adjust logging levels at run-time. For now, you have to do these things manually. For now, search for "log" in services/datareporting/DataReportingService.js to see how it all works.
Flags: needinfo?(gps)
I've used (and slightly modified) a fork of log4moz in the Thunderbird codebase, and the Addon Manager has its own logging framework (http://dxr.mozilla.org/mozilla-central/source/toolkit/mozapps/extensions/AddonLogging.jsm). I like the ability to control logging through preferences as implemented in https://mxr.mozilla.org/comm-central/source/mailnews/db/gloda/modules/log4moz.js; aside from that I'd be happy to switch to toolkit/modules/Log.jsm.
Flags: needinfo?(irving)
log4moz.js was renamed to Log.jsm.
We've switched to console implementation from devtools defined under: resource://gre/modules/devtools/Console.jsm It's pretty good and includes stack traces, also outputs interactive objects into browser console. I don't know if it's compatible with workers though. Cc-ing Mihai as I believe he'll know that.
Flags: needinfo?(rFobic) → needinfo?(mihai.sucan)
Can you Cu.import() Console.jsm from workers? If yes, you should be able to use it for the purpose of logging to the terminal. I don't think it works with the browser console because we don't shuffle the objects cross-process. It would be nice if we could somehow attach the console to the workers.
Flags: needinfo?(mihai.sucan)
No, we can't Cu.import() anything from workers. However, a quick look at the code seems to indicate that most of it could work on workers, once bug 620935 has landed.
Severity: normal → S3

As far as I know, Cu.reportError is basically the equivalent of console.error and provides the stack. If there's specific issues with it, we should file those, but I'm marking this as WFM as I believe the no-stack is no longer an issue.

Status: NEW → RESOLVED
Closed: 2 years ago
Resolution: --- → WORKSFORME
You need to log in before you can comment on or make changes to this bug.