mirror of
https://github.com/laurent22/joplin.git
synced 2025-03-26 21:12:59 +02:00
Remove old log entries
This commit is contained in:
parent
c2ba2105ff
commit
f600689323
@ -48,7 +48,7 @@ class LogScreenComponent extends BaseScreenComponent {
|
||||
};
|
||||
return (
|
||||
<View style={{flexDirection: 'row', paddingLeft: 1, paddingRight: 1, paddingTop:0, paddingBottom:0 }}>
|
||||
<Text style={style}>{time.formatMsToLocal(item.timestamp, 'MM-DDTHH:mm') + ': ' + item.message}</Text>
|
||||
<Text style={style}>{time.formatMsToLocal(item.timestamp, 'MM-DDTHH:mm:ss') + ': ' + item.message}</Text>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ class Logger {
|
||||
this.targets_ = [];
|
||||
this.level_ = Logger.LEVEL_ERROR;
|
||||
this.fileAppendQueue_ = []
|
||||
this.lastDbCleanup_ = time.unixMs();
|
||||
}
|
||||
|
||||
static fsDriver() {
|
||||
@ -111,7 +112,23 @@ class Logger {
|
||||
target.vorpal.log(...object);
|
||||
} else if (target.type == 'database') {
|
||||
let msg = this.objectsToString(...object);
|
||||
target.database.exec('INSERT INTO logs (`source`, `level`, `message`, `timestamp`) VALUES (?, ?, ?, ?)', [target.source, level, msg, time.unixMs()]);
|
||||
|
||||
let queries = [{
|
||||
sql: 'INSERT INTO logs (`source`, `level`, `message`, `timestamp`) VALUES (?, ?, ?, ?)',
|
||||
params: [target.source, level, msg, time.unixMs()],
|
||||
}];
|
||||
|
||||
const now = time.unixMs();
|
||||
if (now - this.lastDbCleanup_ > 1000 * 60 * 60) {
|
||||
this.lastDbCleanup_ = now;
|
||||
const dayKeep = 14;
|
||||
queries.push({
|
||||
sql: 'DELETE FROM logs WHERE `timestamp` < ?',
|
||||
params: [now - 1000 * 60 * 60 * 24 * dayKeep],
|
||||
});
|
||||
}
|
||||
|
||||
target.database.transactionExecBatch(queries);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user