Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Desktop, Mobile: Resolves #10664: Allow user to generate deletion logs #11083

Open
wants to merge 9 commits into
base: dev
Choose a base branch
from

Conversation

pedr
Copy link
Collaborator

@pedr pedr commented Sep 19, 2024

Resolves #10664

Summary

We are adding this new feature on Desktop and Mobile to help users share logs about deletion when they might want some help figuring out what is happening.

To do that, on mobile I created a new Log button on the Tools submenu that filters every DeleteAction event.

On Desktop, I created a Desktop-specific command that reads the log of the active profile and filters every line with the DeleteAction event, creating a new deletion_logs.txt file on the current profile directory.

Testing

I only did manual tests, like:

1 - Create a notebook and a new note
2 - Send the note to the trash
3 - Empty the trash
4 - Create a new note, and send it to the trash
5 - Access the new log screen on mobile or Export deletion logs on the desktop
6 - Only the note that isn't in trash anymore (because it was permanently deleted) should be logged

@pedr pedr requested a review from laurent22 September 19, 2024 20:52
Comment on lines 18 to 26
if (!Logger.globalLogger) {
throw new Error('Could not find global logger');
}

const fileTarget = Logger.globalLogger.targets().find(t => t.type === TargetType.File);

if (!fileTarget || !fileTarget.path) {
throw new Error('Log file target not found');
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the log file was recently rotated, you won't get the information. Maybe instead just directly get log.txt and the latest log-*.txt from the profile directory?


await shim.fsDriver().writeFile(deletionLogPath, deletionLog, 'utf8');

await void bridge().openItem(Setting.value('profileDir'));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead please open the file you've just created. Seems a bit random to open the profile directory as the user won't know why we're doing this

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also no await void please

Comment on lines 11 to 12
name: 'exportDeletionLogs',
label: () => _('Export deletion logs'),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be singular deletion log. Also the filename should be singular

@pedr
Copy link
Collaborator Author

pedr commented Sep 20, 2024

I updated the PR getting all the log files, including the rotations one. I also included a function to order by the timestamp in the log filename (while every time I tested it was already in the right order, I thought it would be better to include this logic there in case something changes)

Since I'm building the path with pure strings (aka: ${Setting.value('profileDir')}/${filePath}), in the afternoon I will be testing the implementation on windows also

Comment on lines 17 to 27
const logsOrderedByTimestamp = (logFiles: Stat[]) => {
return logFiles.sort((a, b) => {
const aTimestamp = a.path.match(/\d+/);
const bTimestamp = b.path.match(/\d+/);

if (!aTimestamp) return 1;
if (!bTimestamp) return -1;

return parseInt(aTimestamp[0], 10) - parseInt(bTimestamp[0], 10);
});
};
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be the same to sort alphabetically?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, thanks for pointing it out, I'm removing this in favour of sort()

Comment on lines 44 to 52
if (!Logger.globalLogger) {
throw new Error('Could not find global logger');
}

const fileTarget = Logger.globalLogger.targets().find(t => t.type === TargetType.File);

if (!fileTarget || !fileTarget.path) {
throw new Error('Log file target not found');
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get why this is still here

Comment on lines 61 to 66
for (const file of orderedLogs) {

const deletionLines = await getDeletionLines(file.path);

allDeletionLines += deletionLines;
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've suggested taking log.txt and the latest log-*.txt, nothing more. We don't need to look at the last 2 years of logs.

Copy link
Owner

@laurent22 laurent22 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests?

Comment on lines 29 to 31
if (!Logger.globalLogger) {
throw new Error('Could not find global logger');
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, why do you need this check for? You don't use the logger anywhere in that code below.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Generate deletion log
2 participants