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

Cleanup old log files #3434

Closed
florelis opened this issue Jul 13, 2023 · 2 comments
Closed

Cleanup old log files #3434

florelis opened this issue Jul 13, 2023 · 2 comments
Labels
Issue-Feature This is a feature request for the Windows Package Manager client.
Milestone

Comments

@florelis
Copy link
Member

Description of the new feature / enhancement

(Assuming we're not doing it already and I just don't know about it...)

If we're not cleaning up old log files, the log folder will just keep growing in size indefinitely. I frequently delete old logs manually when I'm going through new logs, so I don't know how bad this can get wrt space.

Proposed technical implementation details

No response

@florelis florelis added the Issue-Feature This is a feature request for the Windows Package Manager client. label Jul 13, 2023
@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs-Triage Issue need to be triaged label Jul 13, 2023
@Trenly
Copy link
Contributor

Trenly commented Jul 13, 2023

Cleans up after 7 days

// Initiate the background cleanup of the log file location.
Logging::FileLogger::BeginCleanup();

void FileLogger::BeginCleanup(const std::filesystem::path& filePath)
{
std::thread([filePath]()
{
try
{
auto now = std::filesystem::file_time_type::clock::now();
// Remove all files that are older than 7 days from the standard log location.
for (auto& file : std::filesystem::directory_iterator{ filePath })
{
if (file.is_regular_file() &&
now - file.last_write_time() > (7 * 24h))
{
std::filesystem::remove(file.path());
}
}
}
// Just throw out everything
catch (...) {}
}).detach();
}

@florelis
Copy link
Member Author

Oh, nice! Thanks, I didn't know we had that already. Should have tried looking up in the code before opening the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Feature This is a feature request for the Windows Package Manager client.
Projects
None yet
Development

No branches or pull requests

3 participants