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
|
|
@ -1,39 +1,73 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('preferencesLogs',
|
||||
function($scope, historicLog, platformInfo) {
|
||||
function($scope, historicLog, lodash, configService, gettextCatalog) {
|
||||
|
||||
var config = configService.getSync();
|
||||
var logLevels = historicLog.getLevels();
|
||||
var selectedLevel;
|
||||
|
||||
$scope.logOptions = lodash.indexBy(logLevels, 'level');
|
||||
|
||||
var filterLogs = function(weight) {
|
||||
$scope.filteredLogs = historicLog.get(weight);
|
||||
};
|
||||
|
||||
$scope.setOptionSelected = function(level) {
|
||||
var weight = $scope.logOptions[level].weight;
|
||||
$scope.fillClass = 'fill-bar-' + level;
|
||||
filterLogs(weight);
|
||||
lodash.each($scope.logOptions, function(opt) {
|
||||
opt.selected = opt.weight <= weight ? true : false;
|
||||
opt.head = opt.weight == weight;
|
||||
});
|
||||
|
||||
// Save the setting.
|
||||
var opts = {
|
||||
log: {
|
||||
filter: level
|
||||
}
|
||||
};
|
||||
configService.set(opts, function(err) {
|
||||
if (err) $log.debug(err);
|
||||
});
|
||||
};
|
||||
|
||||
$scope.prepareLogs = function() {
|
||||
var log = 'Copay Session Logs\n Be careful, this could contain sensitive private data\n\n';
|
||||
log += '\n\n';
|
||||
log += historicLog.get().map(function(v) {
|
||||
return '[' + v.timestamp + '][' + v.level + ']' + v.msg;
|
||||
}).join('\n');
|
||||
|
||||
return log;
|
||||
};
|
||||
|
||||
$scope.sendLogs = function() {
|
||||
var body = $scope.prepareLogs();
|
||||
|
||||
window.plugins.socialsharing.shareViaEmail(
|
||||
body,
|
||||
'Copay Logs',
|
||||
null, // TO: must be null or an array
|
||||
null, // CC: must be null or an array
|
||||
null, // BCC: must be null or an array
|
||||
null, // FILES: can be null, a string, or an array
|
||||
function() {},
|
||||
function() {}
|
||||
);
|
||||
};
|
||||
|
||||
$scope.showOptionsMenu = function() {
|
||||
$scope.showOptions = true;
|
||||
};
|
||||
|
||||
$scope.$on("$ionicView.beforeEnter", function(event, data) {
|
||||
$scope.isCordova = platformInfo.isCordova;
|
||||
selectedLevel = lodash.has(config, 'log.filter') ? historicLog.getLevel(config.log.filter) : historicLog.getDefaultLevel();
|
||||
$scope.setOptionSelected(selectedLevel.level);
|
||||
});
|
||||
|
||||
$scope.$on("$ionicView.enter", function(event, data) {
|
||||
$scope.logs = historicLog.get();
|
||||
|
||||
$scope.prepare = function() {
|
||||
var log = 'Copay Session Logs\n Be careful, this could contain sensitive private data\n\n';
|
||||
log += '\n\n';
|
||||
log += $scope.logs.map(function(v) {
|
||||
return v.msg;
|
||||
}).join('\n');
|
||||
|
||||
return log;
|
||||
};
|
||||
|
||||
$scope.sendLogs = function() {
|
||||
var body = $scope.prepare();
|
||||
|
||||
window.plugins.socialsharing.shareViaEmail(
|
||||
body,
|
||||
'Copay Logs',
|
||||
null, // TO: must be null or an array
|
||||
null, // CC: must be null or an array
|
||||
null, // BCC: must be null or an array
|
||||
null, // FILES: can be null, a string, or an array
|
||||
function() {},
|
||||
function() {}
|
||||
);
|
||||
};
|
||||
|
||||
filterLogs(selectedLevel.weight);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
29
src/js/directives/logOptions.js
Normal file
29
src/js/directives/logOptions.js
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.directives')
|
||||
.directive('logOptions', function($timeout, platformInfo) {
|
||||
return {
|
||||
restrict: 'E',
|
||||
templateUrl: 'views/includes/logOptions.html',
|
||||
transclude: true,
|
||||
scope: {
|
||||
show: '=logOptionsShow',
|
||||
options: '=logOptions',
|
||||
fillClass: '=logOptionsFillClass',
|
||||
onSelect: '=logOptionsOnSelect',
|
||||
onCopy: '=logOptionsOnCopy',
|
||||
onSend: '=logOptionsOnSend'
|
||||
},
|
||||
link: function(scope, element, attrs) {
|
||||
scope.isCordova = platformInfo.isCordova;
|
||||
|
||||
scope.hide = function() {
|
||||
scope.show = false;
|
||||
};
|
||||
|
||||
scope.getFillClass = function(index) {
|
||||
scope.onSelect(index);
|
||||
};
|
||||
}
|
||||
};
|
||||
});
|
||||
|
|
@ -44,7 +44,8 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
|
|||
function($delegate, platformInfo) {
|
||||
var historicLog = historicLogProvider.$get();
|
||||
|
||||
['debug', 'info', 'warn', 'error', 'log'].forEach(function(level) {
|
||||
historicLog.getLevels().forEach(function(levelDesc) {
|
||||
var level = levelDesc.level;
|
||||
if (platformInfo.isDevel && level == 'error') return;
|
||||
|
||||
var orig = $delegate[level];
|
||||
|
|
|
|||
|
|
@ -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