mirror of https://github.com/BTCPrivate/copay.git
Merge pull request #6417 from ajp8164/feat/improved-log
Enhance logging with timestamps and filtering.
This commit is contained in:
commit
e2cd5650ed
|
@ -1,39 +1,73 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copayApp.controllers').controller('preferencesLogs',
|
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.$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.$on("$ionicView.enter", function(event, data) {
|
||||||
$scope.logs = historicLog.get();
|
filterLogs(selectedLevel.weight);
|
||||||
|
|
||||||
$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() {}
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -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) {
|
function($delegate, platformInfo) {
|
||||||
var historicLog = historicLogProvider.$get();
|
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;
|
if (platformInfo.isDevel && level == 'error') return;
|
||||||
|
|
||||||
var orig = $delegate[level];
|
var orig = $delegate[level];
|
||||||
|
|
|
@ -87,6 +87,10 @@ angular.module('copayApp.services').factory('configService', function(storageSer
|
||||||
emailNotifications: {
|
emailNotifications: {
|
||||||
enabled: false,
|
enabled: false,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
log: {
|
||||||
|
filter: 'debug',
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
var configCache = null;
|
var configCache = null;
|
||||||
|
|
|
@ -1,18 +1,54 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
var logs = [];
|
var logs = [];
|
||||||
angular.module('copayApp.services')
|
angular.module('copayApp.services')
|
||||||
.factory('historicLog', function historicLog() {
|
.factory('historicLog', function historicLog(lodash) {
|
||||||
var root = {};
|
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) {
|
root.add = function(level, msg) {
|
||||||
logs.push({
|
logs.push({
|
||||||
|
timestamp: new Date().toISOString(),
|
||||||
level: level,
|
level: level,
|
||||||
msg: msg,
|
msg: msg,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
root.get = function() {
|
root.get = function(filterWeight) {
|
||||||
return logs;
|
var filteredLogs = logs;
|
||||||
|
if (filterWeight != undefined) {
|
||||||
|
filteredLogs = lodash.filter(logs, function(l) {
|
||||||
|
return weight[l.level] <= filterWeight;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return filteredLogs;
|
||||||
};
|
};
|
||||||
|
|
||||||
return root;
|
return root;
|
||||||
|
|
|
@ -134,7 +134,7 @@ angular.module('copayApp.services')
|
||||||
wallet.setNotificationsInterval(UPDATE_PERIOD);
|
wallet.setNotificationsInterval(UPDATE_PERIOD);
|
||||||
wallet.openWallet(function(err) {
|
wallet.openWallet(function(err) {
|
||||||
if (wallet.status !== true)
|
if (wallet.status !== true)
|
||||||
$log.log('Wallet + ' + walletId + ' status:' + wallet.status)
|
$log.debug('Wallet + ' + walletId + ' status:' + wallet.status)
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
@import "gravatar"
|
@import "gravatar";
|
||||||
|
|
|
@ -0,0 +1,62 @@
|
||||||
|
#check-bar {
|
||||||
|
$bar-widths: (
|
||||||
|
// defined by user, example:
|
||||||
|
// error: 10%,
|
||||||
|
// warn: 37%,
|
||||||
|
// info: 65%,
|
||||||
|
// debug: 90%
|
||||||
|
);
|
||||||
|
.item {
|
||||||
|
padding: 40px;
|
||||||
|
}
|
||||||
|
.checkbox-icon {
|
||||||
|
width: 22px;
|
||||||
|
height: 22px;
|
||||||
|
}
|
||||||
|
.checkbox-icon:after {
|
||||||
|
border: none;
|
||||||
|
}
|
||||||
|
.check-bar {
|
||||||
|
position: relative;
|
||||||
|
.initial-bar-default {
|
||||||
|
border: 2px solid $v-success-color;
|
||||||
|
width: 0%;
|
||||||
|
top: 40px;
|
||||||
|
z-index: 99;
|
||||||
|
border-radius: 10px;
|
||||||
|
position: absolute;
|
||||||
|
}
|
||||||
|
.initial-bar {
|
||||||
|
}
|
||||||
|
@each $name, $bar-width in $bar-widths {
|
||||||
|
.fill-bar-#{$name} {
|
||||||
|
width: $bar-width !important;
|
||||||
|
transition: width .2s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.base-bar {
|
||||||
|
position: absolute;
|
||||||
|
width: 100%;
|
||||||
|
border-bottom: 2px solid #f2f2f2;
|
||||||
|
top: 41px;
|
||||||
|
z-index: 98;
|
||||||
|
left: 0px;
|
||||||
|
}
|
||||||
|
&.list {
|
||||||
|
margin-top: 20px;
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
.custom-checkbox {
|
||||||
|
text-align: -webkit-center;
|
||||||
|
.item {
|
||||||
|
border-style: none;
|
||||||
|
z-index: 999;
|
||||||
|
background-color: inherit;
|
||||||
|
}
|
||||||
|
label {
|
||||||
|
padding-top: 5px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,88 @@
|
||||||
|
log-options {
|
||||||
|
|
||||||
|
$border-color: #EFEFEF;
|
||||||
|
|
||||||
|
.bp-action-sheet__sheet {
|
||||||
|
padding-left: 2rem;
|
||||||
|
padding-right: .75rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.entry {
|
||||||
|
border: 0;
|
||||||
|
padding-right: 0;
|
||||||
|
padding-top: 0;
|
||||||
|
padding-bottom: 0;
|
||||||
|
margin-bottom: 1px;
|
||||||
|
overflow: visible;
|
||||||
|
|
||||||
|
> i {
|
||||||
|
color: $v-accent-color;
|
||||||
|
padding: 0 0 5px 0;
|
||||||
|
margin-left: -5px;
|
||||||
|
|
||||||
|
> img {
|
||||||
|
height: 39px;
|
||||||
|
width: 39px;
|
||||||
|
padding: 4px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.entry-inner {
|
||||||
|
display: flex;
|
||||||
|
position: relative;
|
||||||
|
padding-top: 16px;
|
||||||
|
padding-bottom: 16px;
|
||||||
|
|
||||||
|
&::after {
|
||||||
|
display: block;
|
||||||
|
position: absolute;
|
||||||
|
width: 100%;
|
||||||
|
height: 1px;
|
||||||
|
background: $border-color;
|
||||||
|
bottom: 0;
|
||||||
|
right: 0;
|
||||||
|
content: '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.entry-details {
|
||||||
|
flex-grow: 1;
|
||||||
|
|
||||||
|
.entry-name {
|
||||||
|
padding-bottom: 5px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#check-bar {
|
||||||
|
$bar-widths: (
|
||||||
|
// Order must match weight, see services/historicLog.js
|
||||||
|
error: 10%,
|
||||||
|
warn: 35%,
|
||||||
|
info: 65%,
|
||||||
|
debug: 90%
|
||||||
|
);
|
||||||
|
.check-bar {
|
||||||
|
.initial-bar {
|
||||||
|
border: 2px solid $v-accent-color;
|
||||||
|
}
|
||||||
|
@each $name, $bar-width in $bar-widths {
|
||||||
|
.fill-bar-#{$name} {
|
||||||
|
width: $bar-width !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.head .checkbox-icon {
|
||||||
|
width: 22px;
|
||||||
|
height: 22px;
|
||||||
|
top: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.checkbox-icon {
|
||||||
|
width: 10px;
|
||||||
|
height: 10px;
|
||||||
|
top: 6px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -123,6 +123,20 @@
|
||||||
color: #00901B;
|
color: #00901B;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.log-bg {
|
||||||
|
background: white;
|
||||||
|
}
|
||||||
|
.log-entry {
|
||||||
|
font-size: 12px;
|
||||||
|
line-height: 18px;
|
||||||
|
border: none;
|
||||||
|
}
|
||||||
|
.log-timestamp {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
.log-level {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#tab-settings {
|
#tab-settings {
|
||||||
|
|
|
@ -48,3 +48,5 @@
|
||||||
@import "integrations/integrations";
|
@import "integrations/integrations";
|
||||||
@import "custom-amount";
|
@import "custom-amount";
|
||||||
@import "includes/pin";
|
@import "includes/pin";
|
||||||
|
@import "includes/logOptions";
|
||||||
|
@import "includes/checkBar";
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
<div id="check-bar">
|
||||||
|
<div class="check-bar list">
|
||||||
|
<div ng-class="fillClass" class="initial-bar-default initial-bar"></div>
|
||||||
|
<div class="base-bar"></div>
|
||||||
|
<div class="custom-checkbox" ng-repeat="option in options track by $index" ng-class="{'head': option.head}">
|
||||||
|
<label>{{option.label}}</label>
|
||||||
|
<ion-checkbox ng-model="option.selected" ng-change="getFillClass(option.level)"></ion-checkbox>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
|
@ -0,0 +1,21 @@
|
||||||
|
<action-sheet action-sheet-show="show" class="log-options">
|
||||||
|
<img class="back-arrow" src="img/icon-back-arrow.svg" ng-click="hide()">
|
||||||
|
<div class="header" translate="">Log options</div>
|
||||||
|
<div ng-include="'views/includes/checkBar.html'"></div>
|
||||||
|
<a class="item item-icon-left entry no-border" copy-to-clipboard="onCopy()" ng-click="hide()">
|
||||||
|
<i class="icon ion-clipboard"></i>
|
||||||
|
<div class="entry-inner">
|
||||||
|
<div class="entry-details">
|
||||||
|
<div class="entry-name" translate>Copy to clipboard</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
<a class="item item-icon-left entry no-border" ng-click="onSend(); hide()" ng-show="isCordova">
|
||||||
|
<i class="icon ion-ios-email-outline"></i>
|
||||||
|
<div class="entry-inner">
|
||||||
|
<div class="entry-details">
|
||||||
|
<div class="entry-name" translate>Send by email</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
</action-sheet>
|
|
@ -1,23 +1,23 @@
|
||||||
<ion-view class="settings" show-tabs>
|
<ion-view class="settings" hide-tabs>
|
||||||
<ion-nav-bar class="bar-royal">
|
<ion-nav-bar class="bar-royal">
|
||||||
<ion-nav-title>{{'Session Log' | translate}}</ion-nav-title>
|
<ion-nav-title>{{'Session Log' | translate}}</ion-nav-title>
|
||||||
<ion-nav-back-button>
|
<ion-nav-back-button>
|
||||||
</ion-nav-back-button>
|
</ion-nav-back-button>
|
||||||
|
<ion-nav-buttons side="secondary">
|
||||||
|
<button class="button back-button" ng-click="showOptionsMenu()">
|
||||||
|
<i class="icon ion-ios-more"></i>
|
||||||
|
</button>
|
||||||
|
</ion-nav-buttons>
|
||||||
</ion-nav-bar>
|
</ion-nav-bar>
|
||||||
<ion-content>
|
<ion-content class="log-bg">
|
||||||
<div class="settings-button-group">
|
|
||||||
<button class="button button-standard button-primary" copy-to-clipboard="prepare()">
|
|
||||||
<span translate>Copy to clipboard</span>
|
|
||||||
</button>
|
|
||||||
<button class="button button-standard button-secondary" ng-show="isCordova" ng-click="sendLogs()">
|
|
||||||
<span translate>Send by email</span>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
<div class="list">
|
<div class="list">
|
||||||
<div class="item item-text-wrap enable_text_select">
|
<div class="item item-text-wrap enable_text_select log-entry">
|
||||||
<ul>
|
<div class="centered" ng-show="filteredLogs.length == 0" translate>No entries for this log level <a ng-click="showOptionsMenu()">filter setting</a>.</div>
|
||||||
<li ng-repeat="l in logs">
|
<ul ng-show="filteredLogs.length > 0">
|
||||||
<span ng-class="{'energized': l.level=='warn', 'dark': l.level=='debug', 'positive': l.level=='info', 'assertive': l.level=='error' }">
|
<li ng-repeat="l in filteredLogs">
|
||||||
|
<span ng-class="{'energized': l.level=='warn', 'dark': l.level=='debug', 'positive': l.level=='info', 'assertive': l.level=='error'}">
|
||||||
|
<span class="log-timestamp">[{{l.timestamp}}]</span>
|
||||||
|
<span class="log-level">[{{l.level}}]</span>
|
||||||
{{l.msg}}
|
{{l.msg}}
|
||||||
</span>
|
</span>
|
||||||
</li>
|
</li>
|
||||||
|
@ -25,4 +25,12 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</ion-content>
|
</ion-content>
|
||||||
|
<log-options
|
||||||
|
log-options-show="showOptions"
|
||||||
|
log-options="logOptions"
|
||||||
|
log-options-fill-class="fillClass"
|
||||||
|
log-options-on-select="setOptionSelected"
|
||||||
|
log-options-on-copy="prepareLogs"
|
||||||
|
log-options-on-send="sendLogs">
|
||||||
|
</log-options>
|
||||||
</ion-view>
|
</ion-view>
|
||||||
|
|
Loading…
Reference in New Issue