1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

Mobile: Allow filtering log by warning/error

This commit is contained in:
Laurent Cozic 2018-01-31 19:51:29 +00:00
parent 551fabdfc9
commit dac1cd7668
3 changed files with 31 additions and 5 deletions

View File

@ -23,6 +23,7 @@ class LogScreenComponent extends BaseScreenComponent {
});
this.state = {
dataSource: ds,
showErrorsOnly: false,
};
this.styles_ = {};
}
@ -62,13 +63,24 @@ class LogScreenComponent extends BaseScreenComponent {
this.resfreshLogEntries();
}
resfreshLogEntries() {
reg.logger().lastEntries(1000).then((entries) => {
resfreshLogEntries(showErrorsOnly = null) {
if (showErrorsOnly === null) showErrorsOnly = this.state.showErrorsOnly;
let levels = [Logger.LEVEL_DEBUG, Logger.LEVEL_INFO, Logger.LEVEL_WARN, Logger.LEVEL_ERROR];
if (showErrorsOnly) levels = [Logger.LEVEL_WARN, Logger.LEVEL_ERROR]
reg.logger().lastEntries(1000, { levels: levels }).then((entries) => {
const newDataSource = this.state.dataSource.cloneWithRows(entries);
this.setState({ dataSource: newDataSource });
});
}
toggleErrorsOnly() {
const showErrorsOnly = !this.state.showErrorsOnly;
this.setState({ showErrorsOnly: showErrorsOnly });
this.resfreshLogEntries(showErrorsOnly);
}
render() {
let renderRow = (item) => {
let textStyle = this.styles().rowText;
@ -91,7 +103,14 @@ class LogScreenComponent extends BaseScreenComponent {
renderRow={renderRow}
enableEmptySections={true}
/>
<Button title={_("Refresh")} onPress={() => { this.resfreshLogEntries(); }}/>
<View style={{flexDirection: 'row'}}>
<View style={{flex:1, marginRight: 5 }}>
<Button title={_("Refresh")} onPress={() => { this.resfreshLogEntries(); }}/>
</View>
<View style={{flex:1}}>
<Button title={this.state.showErrorsOnly ? _("Show all") : _("Errors only")} onPress={() => { this.toggleErrorsOnly(); }}/>
</View>
</View>
</View>
);
}

View File

@ -85,11 +85,15 @@ class Logger {
}
// Only for database at the moment
async lastEntries(limit = 100) {
async lastEntries(limit = 100, options = null) {
if (options === null) options = {};
if (!options.levels) options.levels = [Logger.LEVEL_DEBUG, Logger.LEVEL_INFO, Logger.LEVEL_WARN, Logger.LEVEL_ERROR];
if (!options.levels.length) return [];
for (let i = 0; i < this.targets_.length; i++) {
const target = this.targets_[i];
if (target.type == 'database') {
let sql = 'SELECT * FROM logs ORDER BY timestamp DESC';
let sql = 'SELECT * FROM logs WHERE level IN (' + options.levels.join(',') + ') ORDER BY timestamp DESC';
if (limit !== null) sql += ' LIMIT ' + limit
return await target.database.selectAll(sql);
}

View File

@ -72,6 +72,9 @@ class DecryptionWorker {
for (let i = 0; i < items.length; i++) {
const item = items[i];
if (['edf44b7a0e4f8cbf248e206cd8dfa800', '2ccb3c9af0b1adac2ec6b66a5961fbb1'].indexOf(item.id) >= 0) continue; // Temp hack
const ItemClass = BaseItem.itemClass(item);
this.logger().debug('DecryptionWorker: decrypting: ' + item.id + ' (' + ItemClass.tableName() + ')');
try {