Make debug log persistent

Save log entries in indexedDB rather than just in memory. Reload them
whenever the background page is refreshed.

// FREEBIE
This commit is contained in:
lilia 2016-02-02 17:55:27 -08:00
parent 86132a38a8
commit 87ddcef333
4 changed files with 50 additions and 7 deletions

View File

@ -311,9 +311,9 @@
<div><button class='close'>{{ close }}</button></div>
</div>
</script>
<script type='text/javascript' src='js/debugLog.js'></script>
<script type='text/javascript' src='js/components.js'></script>
<script type='text/javascript' src='js/database.js'></script>
<script type='text/javascript' src='js/debugLog.js'></script>
<script type='text/javascript' src='js/storage.js'></script>
<script type='text/javascript' src='js/axolotl_store.js'></script>
<script type='text/javascript' src='js/libtextsecure.js'></script>

View File

@ -4,6 +4,7 @@
;(function() {
'use strict';
console.log('background page reloaded');
// register some chrome listeners
if (chrome.notifications) {
chrome.notifications.onClicked.addListener(function() {

View File

@ -100,6 +100,12 @@
});
storage.fetch();
}
},
{
version: "7.0",
migrate: function(transaction, next) {
transaction.db.createObjectStore("debug");
}
}
];
}());

View File

@ -3,22 +3,58 @@
*/
(function () {
'use strict';
var LogEntry = Backbone.Model.extend({
database: Whisper.Database,
storeName: 'debug',
printTime: function() {
try {
return new Date(this.get('time')).toISOString();
} catch(e) {
return '';
}
},
printValue: function() {
return this.get('value') || '';
}
});
var DebugLog = Backbone.Collection.extend({
database: Whisper.Database,
storeName: 'debug',
model: LogEntry,
comparator: 'time',
initialize: function() {
this.fetch({remove: false});
},
log: function(str) {
this.add({time: Date.now(), value: str}).save();
if (this.length > MAX_MESSAGES) {
this.at(0).destroy();
}
},
print: function() {
return this.map(function(entry) {
return entry.printTime() + ' ' + entry.printValue();
}).join('\n');
}
});
var MAX_MESSAGES = 1000;
var PHONE_REGEX = /\+\d{7,12}(\d{3})/g;
var debugLog = [];
var log = new DebugLog();
if (window.console) {
console._log = console.log;
console.log = function(){
console._log.apply(this, arguments);
if (debugLog.length > MAX_MESSAGES) {
debugLog.shift();
}
var args = Array.prototype.slice.call(arguments);
var str = args.join(' ').replace(PHONE_REGEX, "+[REDACTED]$1");
debugLog.push(str);
log.log(str);
};
console.get = function() {
return window.navigator.userAgent + '\n' + debugLog.join('\n');
return window.navigator.userAgent +
' Signal-Desktop/' + chrome.runtime.getManifest().version +
'\n' + log.print();
};
console.post = function(log) {
if (log === undefined) {