-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement consoleExport to file based on https://code.google.com/p/fb…
- Loading branch information
1 parent
5aee5a3
commit 22bddbd
Showing
6 changed files
with
168 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,3 +30,4 @@ | |
# Extensions | ||
/extension/firebug@software.joehewitt.com | ||
|
||
release/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
VERSION=0.5 | ||
RELEASE=b5 | ||
RELEASE=b6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
// ************************************************************************************************ | ||
}}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22bddbd
There was a problem hiding this comment.
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