文件
mynode/packages/lib/utils/ActionLogger.ts
chen 301194963b
一些检查失败了
automerge / automerge (push) Has been cancelled
react-native-android-build-apk / AssembleRelease (push) Has been cancelled
Build macOS M1 / Main (push) Has been cancelled
Joplin Continuous Integration / Main (macos-15-intel) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-11-vs2026-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-2025) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04-arm) (push) Has been cancelled
Joplin UI tests / Main (ubuntu-22.04) (push) Has been cancelled
Joplin UI tests / Main (windows-2025) (push) Has been cancelled
Joplin UI tests / Mobile (push) Has been cancelled
Close stale issues / ProcessStaleIssues (push) Has been cancelled
feat: Initial clean release of CHM
2026-11-04 11:29:39 +08:00

62 行
1.5 KiB
TypeScript

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[]) {
if (!ActionLogger.enabled_) {
return;
}
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;
}
// Disabling the action logger globally can be useful on Joplin Server/Cloud
// when many deletions are expected (e.g. for email-to-note).
private static enabled_ = true;
public static set enabled(v: boolean) {
this.enabled_ = v;
}
public static get enabled() {
return this.enabled_;
}
}