Skip to content

Commit

Permalink
Implement consoleExport to file based on https://code.google.com/p/fb…
Browse files Browse the repository at this point in the history
  • Loading branch information
ptrstpp950 committed Aug 13, 2015
1 parent 5aee5a3 commit 22bddbd
Show file tree
Hide file tree
Showing 6 changed files with 168 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@
# Extensions
/extension/firebug@software.joehewitt.com

release/
2 changes: 1 addition & 1 deletion ant.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
VERSION=0.5
RELEASE=b5
RELEASE=b6
119 changes: 119 additions & 0 deletions chrome/content/consoleexport/consoleDumper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/* See license.txt for terms of usage */

FBL.ns(function() { with (FBL) {

// ************************************************************************************************
// Constants

const Cc = Components.classes;
const Ci = Components.interfaces;

var prefDomain = "extensions.firebug.consoleexport";

// ************************************************************************************************
// Module implementation

/**
* This object implements dumping messages to a file
* This object is also responsible for building XML messages.
*/
Firebug.ConsoleExport.Dumper = extend(Firebug.Module,
/** @lends Firebug.ConsoleExport.Dumper */
{
initialize: function(){

if (FBTrace.DBG_CONSOLEEXPORT)
FBTrace.sysout("initialize consoleexport.Dumper.dump");
this.dumps = [];
Firebug.Module.initialize.apply(this, arguments);

},
shutdown: function(){

Firebug.Module.shutdown.apply(this, arguments);


if (FBTrace.DBG_CONSOLEEXPORT)
FBTrace.sysout("shutdown consoleexport.Dumper.dump with dumps.length="+this.dumps.length);

var path = Firebug.getPref(prefDomain, "logFilePath");
if (!path){
return;
}

var content;
var format = Firebug.getPref(prefDomain, "format")
if (format != null && format.toLowerCase() == "json"){
content = JSON.stringify(this.dumps);
}
else{
content ="<logs>";
for(var i=0; i<this.dumps.length; i++){
content += this.buildPacket(this.dumps[i]);
}
content +="</logs>";
}
this.writeToFile({
path: path,
data: content
});
},
dump: function(data)
{
this.dumps.push(data);
},

// TODO: c&p from consoleUploader, could be moved to some common util
buildPacket: function(data) {
var xml = "<log>";

if (data.className)
xml += "<class>" + data.className + "</class>";

if (data.cat)
xml += "<cat>" + data.cat + "</cat>";

if (data.msg)
xml += "<msg><![CDATA[" + data.msg + "]]></msg>";

if (data.href)
xml += "<href><![CDATA[" + data.href + "]]></href>";

if (data.lineNo)
xml += "<lineNo>" + data.lineNo + "</lineNo>";

if (data.source)
xml += "<source>" + data.source + "</source>";

xml += "</log>";

return xml;
},

writeToFile: function(options) {
try {
var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
file.initWithPath( options.path );
if(file.exists() == false) {
file.create( Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 420);
}
var foStream = Components.classes["@mozilla.org/network/file-output-stream;1"].createInstance(Components.interfaces.nsIFileOutputStream);
foStream.init(file, 0x02 | 0x10, 0666, 0); // open in append mode

var converter = Components.classes["@mozilla.org/intl/converter-output-stream;1"].createInstance(Components.interfaces.nsIConverterOutputStream);
converter.init(foStream, "UTF-8", 0, 0);
converter.writeString( options.data );
converter.close();
}
catch (e) {
if (FBTrace.DBG_CONSOLEEXPORT || FBTrace.DBG_ERRORS)
FBTrace.sysout("consoleexport.writeToFile; EXCEPTION " + e, e);
}
}
});
// ************************************************************************************************
// Registration

Firebug.registerModule(Firebug.ConsoleExport.Dumper);
// ************************************************************************************************
}});
1 change: 1 addition & 0 deletions chrome/content/consoleexport/consoleExport.xul
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<overlay xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script src="chrome://consoleexport/content/consoleExport.js" type="application/x-javascript"/>
<script src="chrome://consoleexport/content/consoleAutomation.js" type="application/x-javascript"/>
<script src="chrome://consoleexport/content/consoleDumper.js" type="application/x-javascript"/>
<script src="chrome://consoleexport/content/consoleListener.js" type="application/x-javascript"/>
<script src="chrome://consoleexport/content/consoleUploader.js" type="application/x-javascript"/>

Expand Down
59 changes: 45 additions & 14 deletions chrome/content/consoleexport/consoleListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ FBL.ns(function() { with (FBL) {
const Cc = Components.classes;
const Ci = Components.interfaces;

var prefDomain = "extensions.firebug.consoleexport";

// ************************************************************************************************
// Module implementation

Expand Down Expand Up @@ -60,14 +62,28 @@ Firebug.ConsoleExport.Listener =
else
message = object.message;

Firebug.ConsoleExport.Uploader.send({
className: className,
cat: object.category,
msg: message,
href: object.href ? object.href : context.getName(),
lineNo: object.lineNo,
source: object.source,
});
var url = Firebug.getPref(prefDomain, "serverURL");
var path = Firebug.getPref(prefDomain, "logFilePath");
if (url) {
Firebug.ConsoleExport.Uploader.send({
className: className,
cat: object.category,
msg: message,
href: object.href ? object.href : context.getName(),
lineNo: object.lineNo,
source: object.source,
});
}
if (path) {
Firebug.ConsoleExport.Dumper.dump({
className: className,
cat: object.category,
msg: object.message,
href: object.href ? object.href : context.getName(),
lineNo: object.lineNo,
source: object.source,
});
}
}
catch (err)
{
Expand All @@ -84,12 +100,27 @@ Firebug.ConsoleExport.Listener =
FBTrace.sysout("consoleexport.Console.Listener.logFormatted; " +
className, objects[0]);

Firebug.ConsoleExport.Uploader.send({
className: className,
cat: "log",
msg: objects[0],
href: context.getName(),
});
var url = Firebug.getPref(prefDomain, "serverURL");
var path = Firebug.getPref(prefDomain, "logFilePath");
if(url)
{
Firebug.ConsoleExport.Uploader.send({
className: className,
cat: "log",
msg: objects[0],
href: context.getName(),
});
}
if (path) {
Firebug.ConsoleExport.Dumper.dump({
className: className,
cat: object.category,
msg: object.message,
href: object.href ? object.href : context.getName(),
lineNo: object.lineNo,
source: object.source,
});
}
},

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Expand Down
1 change: 1 addition & 0 deletions defaults/preferences/consoleexport.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ pref("extensions.firebug.DBG_CONSOLEEXPORT", false);
pref("extensions.firebug.consoleexport.active", false);
pref("extensions.firebug.consoleexport.serverURL", "");
pref("extensions.firebug.consoleexport.format", "xml");
pref("extensions.firebug.consoleexport.logFilePath", "");

1 comment on commit 22bddbd

@SebastianZ
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reference, that patch is fixing issue #9. Obviously this patch also didn't include my remarks from comment 22, therefore I've created issue #20 now.

Sebastian

Please sign in to comment.