Enhance logging with timestamps and filtering.
This commit is contained in:
parent
f9125e1193
commit
b7cfd86f22
14 changed files with 257 additions and 13 deletions
|
|
@ -1,9 +1,32 @@
|
|||
'use strict';
|
||||
var logs = [];
|
||||
angular.module('copayApp.services')
|
||||
.factory('historicLog', function historicLog() {
|
||||
.factory('historicLog', function historicLog(lodash) {
|
||||
var root = {};
|
||||
|
||||
var levels = [
|
||||
{ level: 'info', weight: 0, label: 'Info'},
|
||||
{ level: 'warn', weight: 1, label: 'Warning'},
|
||||
{ level: 'error', weight: 2, label: 'Error'},
|
||||
{ level: 'debug', weight: 3, label: 'Debug', default: true}
|
||||
];
|
||||
|
||||
// Create an array of level weights for performant filtering.
|
||||
var weight = {};
|
||||
for (var i = 0; i < levels.length; i++) {
|
||||
weight[levels[i].level] = levels[i].weight;
|
||||
}
|
||||
|
||||
root.getLevels = function() {
|
||||
return levels;
|
||||
};
|
||||
|
||||
root.getDefaultLevel = function() {
|
||||
return lodash.find(levels, function(l) {
|
||||
return l.default;
|
||||
});
|
||||
};
|
||||
|
||||
root.add = function(level, msg) {
|
||||
logs.push({
|
||||
level: level,
|
||||
|
|
@ -11,8 +34,14 @@ angular.module('copayApp.services')
|
|||
});
|
||||
};
|
||||
|
||||
root.get = function() {
|
||||
return logs;
|
||||
root.get = function(filterWeight) {
|
||||
var filteredLogs = logs;
|
||||
if (filterWeight != undefined) {
|
||||
filteredLogs = lodash.filter(logs, function(l) {
|
||||
return weight[l.level] <= filterWeight;
|
||||
});
|
||||
}
|
||||
return filteredLogs;
|
||||
};
|
||||
|
||||
return root;
|
||||
|
|
|
|||
|
|
@ -134,7 +134,7 @@ angular.module('copayApp.services')
|
|||
wallet.setNotificationsInterval(UPDATE_PERIOD);
|
||||
wallet.openWallet(function(err) {
|
||||
if (wallet.status !== true)
|
||||
$log.log('Wallet + ' + walletId + ' status:' + wallet.status)
|
||||
$log.debug('Wallet + ' + walletId + ' status:' + wallet.status)
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue