1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-07-13 00:10:37 +02:00

Cli,Desktop,Mobile: Resolves #9465: Log user actions (deletions) (#9585)

This commit is contained in:
Henry Heino
2024-03-09 02:33:05 -08:00
committed by GitHub
parent 3222b620b9
commit 75cb639ed2
36 changed files with 182 additions and 59 deletions

View File

@ -0,0 +1,44 @@
import Logger from '@joplin/utils/Logger';
export enum ItemActionType {
Delete = 'DeleteAction',
}
const actionTypeToLogger = {
[ItemActionType.Delete]: Logger.create(ItemActionType.Delete),
};
export default class ActionLogger {
private descriptions: string[] = [];
private constructor(private source: string) { }
public clone() {
const clone = new ActionLogger(this.source);
clone.descriptions = [...this.descriptions];
return clone;
}
// addDescription is used to add labels with information that may not be available
// when .log is called. For example, to include the title of a deleted note.
public addDescription(description: string) {
this.descriptions.push(description);
}
public log(action: ItemActionType, itemIds: string|string[]) {
const logger = actionTypeToLogger[action];
logger.info(`${this.source}: ${this.descriptions.join(',')}; Item IDs: ${JSON.stringify(itemIds)}`);
}
public static from(source: ActionLogger|string|undefined) {
if (!source) {
source = 'Unknown source';
}
if (typeof source === 'string') {
return new ActionLogger(source);
}
return source;
}
}