Merge pull request #6417 from ajp8164/feat/improved-log
Enhance logging with timestamps and filtering.
This commit is contained in:
commit
e2cd5650ed
14 changed files with 356 additions and 47 deletions
|
|
@ -87,6 +87,10 @@ angular.module('copayApp.services').factory('configService', function(storageSer
|
|||
emailNotifications: {
|
||||
enabled: false,
|
||||
},
|
||||
|
||||
log: {
|
||||
filter: 'debug',
|
||||
},
|
||||
};
|
||||
|
||||
var configCache = null;
|
||||
|
|
|
|||
|
|
@ -1,18 +1,54 @@
|
|||
'use strict';
|
||||
var logs = [];
|
||||
angular.module('copayApp.services')
|
||||
.factory('historicLog', function historicLog() {
|
||||
.factory('historicLog', function historicLog(lodash) {
|
||||
var root = {};
|
||||
|
||||
var levels = [
|
||||
{ level: 'error', weight: 0, label: 'Error'},
|
||||
{ level: 'warn', weight: 1, label: 'Warning'},
|
||||
{ level: 'info', weight: 2, label: 'Info', default: true},
|
||||
{ level: 'debug', weight: 3, label: 'Debug'}
|
||||
];
|
||||
|
||||
// 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.getLevel = function(level) {
|
||||
return lodash.find(levels, function(l) {
|
||||
return l.level == level;
|
||||
});
|
||||
};
|
||||
|
||||
root.getDefaultLevel = function() {
|
||||
return lodash.find(levels, function(l) {
|
||||
return l.default;
|
||||
});
|
||||
};
|
||||
|
||||
root.add = function(level, msg) {
|
||||
logs.push({
|
||||
timestamp: new Date().toISOString(),
|
||||
level: level,
|
||||
msg: msg,
|
||||
});
|
||||
};
|
||||
|
||||
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