infocatcher / console_logger Goto Github PK
View Code? Open in Web Editor NEWAdds ability to write certain console messages to log files, restartless extension for Gecko-based applications
License: Other
Adds ability to write certain console messages to log files, restartless extension for Gecko-based applications
License: Other
Part for #3
https://developer.mozilla.org/en-US/docs/JavaScript_OS.File/OS.File_for_the_main_thread
Example:
var file = "D:\\test";
appendAsync(file, "1: " + ts() + " Qwerty Йцукен\n", function() {
appendAsync(file, "2: " + ts() + "\n", function() {
appendAsync(file, "3: " + ts() + "\n");
});
});
function appendAsync(file, data, callback) {
function onFailure(err) {
Components.utils.reportError(err);
callback && callback("");
}
OS.File.open(file, { write: true, append: true }).then(
function onSuccess(osFile) {
var arr = new TextEncoder().encode(data); //~ todo: reuse TextEncoder
osFile.write(arr).then(
function onSuccess(bytesCount) {
osFile.close().then(
function onSuccess() {
callback && callback(data);
},
onFailure
).then(null, onFailure);
},
onFailure
).then(null, onFailure);
},
onFailure
).then(null, onFailure);
}
function ts() {
var d = new Date();
var ms = d.getMilliseconds();
return d.toLocaleFormat("%M:%S:") + "000".substr(String(ms).length) + ms;
}
Part for #3
Part for #3
We currently use window.content
in our consoleLogger.openOptionsInTab()
.
Looks like all console listeners are called at once:
var halt = 0;
var t = [0, 0, 0, 0];
var o1 = {
observe: function(msg) {
Services.tm.mainThread.dispatch({run: function() {
t[2] = performance.now();
stats();
}}, Components.interfaces.nsIThread.DISPATCH_NORMAL);
t[0] = performance.now();
if(halt) {
var stop = performance.now() + halt;
while(performance.now() < stop);
}
Services.console.unregisterListener(this);
stats();
}
};
var o2 = {
observe: function(msg) {
Services.tm.mainThread.dispatch({run: function() {
t[3] = performance.now();
stats();
}}, Components.interfaces.nsIThread.DISPATCH_NORMAL);
t[1] = performance.now();
var stop = performance.now() + 50;
if(halt) {
var stop = performance.now() + halt;
while(performance.now() < stop);
}
Services.console.unregisterListener(this);
stats();
}
};
Services.console.registerListener(o1);
Services.console.registerListener(o2);
function stats() {
if(t[0] && t[1] && t[2] && t[3]) {
var listeners = Math.max(t[0], t[1]);
alert([
"Listener #1: " + t[0].toFixed(2),
"Listener #2: " + t[1].toFixed(2),
"Delayed #1: " + t[2].toFixed(2) + (t[2] > listeners ? " after listeners!" : ""),
"Delayed #2: " + t[3].toFixed(2) + (t[3] > listeners ? " after listeners!" : "")
].join("\n"));
}
}
Services.console.logStringMessage("test");
Example output:
Listener #1: 1964481.64
Listener #2: 1964481.59
Delayed #1: 1964483.19 after listeners!
Delayed #2: 1964483.16 after listeners!
Also there is no reasons to handle notification ASAP.
Something like following:
https://github.com/Infocatcher/Handy_Clicks/blob/0.1.3pre5/chrome/content/setsUtils.js#L523-L558
Since we already have code to copy and remove (#4).
Part for #3
Order of nsIPrefBranch.getChildList() may be "wrong".
Just like on about:config.
Part for #3
Part for #3
We unable to create preferences with such names...
Part for #3
Something like
bootstrap.js
---> core.js // Things around console messages (to not load with extensions.consoleLogger.enabled = false)
---> io.js // File I/O (to load only if found matched console message)
We have nsISessionStore.setGlobalValue()
, nsISessionStore.getGlobalValue()
and nsISessionStore.deleteGlobalValue()
since Firefox 28, see https://bugzilla.mozilla.org/show_bug.cgi?id=899213
See https://developer.mozilla.org/en-US/docs/Tools/Browser_Console#Messages_from_add-ons
resource://gre/modules/devtools/Console.jsm
From 30.0:
/**
* Send a Console API message. This function will send a console-api-log-event
* notification through the nsIObserverService.
*
* @param {string} aLevel
* Message severity level. This is usually the name of the console method
* that was called.
* @param {object} aFrame
* The youngest stack frame coming from Components.stack, as formatted by
* getStack().
* @param {array} aArgs
* The arguments given to the console method.
* @param {object} aOptions
* Object properties depend on the console method that was invoked:
* - timer: for time() and timeEnd(). Holds the timer information.
* - groupName: for group(), groupCollapsed() and groupEnd().
* - stacktrace: for trace(). Holds the array of stack frames as given by
* getStack().
*/
function sendConsoleAPIMessage(aLevel, aFrame, aArgs, aOptions = {})
{
let consoleEvent = {
ID: "jsm",
innerID: aFrame.filename,
level: aLevel,
filename: aFrame.filename,
lineNumber: aFrame.lineNumber,
functionName: aFrame.functionName,
timeStamp: Date.now(),
arguments: aArgs,
};
consoleEvent.wrappedJSObject = consoleEvent;
switch (aLevel) {
case "trace":
consoleEvent.stacktrace = aOptions.stacktrace;
break;
case "time":
case "timeEnd":
consoleEvent.timer = aOptions.timer;
break;
case "group":
case "groupCollapsed":
case "groupEnd":
try {
consoleEvent.groupName = Array.prototype.join.call(aArgs, " ");
}
catch (ex) {
Cu.reportError(ex);
Cu.reportError(ex.stack);
return;
}
break;
}
Services.obs.notifyObservers(consoleEvent, "console-api-log-event", null);
let ConsoleAPIStorage = Cc["@mozilla.org/consoleAPI-storage;1"]
.getService(Ci.nsIConsoleAPIStorage);
ConsoleAPIStorage.recordEvent("jsm", consoleEvent);
}
Part for #3
Part for #3
Add button for each entry:
disabled – no *.log file
enabled – has *.log file, click on button to open it
Also we can notify options window about changes and display something like Log (2)
for 2 new changes.
Part for #3
Just open chrome://consolelogger/content/options.xul in tab, disable extension and check about:memory.
And seems that all work fine for options in separate window.
Part for #3
We already have optionsOpener.xul trick to escape from modal window, so it's easy to just open tab instead of new window.
Special parts:
For extensions.consoleLogger.options.logViewer preference.
Now we have separate panel for our buttons (Add/Remove/Options). We can move all that buttons into built-in panel with OK/Cancel buttons.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.