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

Emulator: Create a Log Backup #2464

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Xphalnos
Copy link
Collaborator

@Xphalnos Xphalnos commented Feb 17, 2025

Like yuzu and other emulators, it is good to have a log backup.
When starting shadPS4, the log of the previous session is renamed to shad_log.old.txt.
This can be useful to compare logs when making changes.
I tried to make the code as understandable as possible.

image

Copy link
Collaborator

@squidbus squidbus left a comment

Choose a reason for hiding this comment

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

Seems fine, although one general thought is maybe we should do this as part of the log system init alongside defining the new log file instead of out in emulator init.

src/emulator.cpp Outdated
#ifdef _WIN32
Common::NtApi::Initialize();
SetPriorityClass(GetCurrentProcess(), ABOVE_NORMAL_PRIORITY_CLASS);
#endif

// Renaming shad_log.txt to shad_log.old.txt when booting.
const auto LogDir = Common::FS::GetUserPath(Common::FS::PathType::LogDir);
const auto CurrentLog = LogDir / "shad_log.txt";
Copy link
Collaborator

Choose a reason for hiding this comment

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

We have a constant LOG_FILE in the path util for this.

Copy link
Collaborator Author

@Xphalnos Xphalnos Feb 17, 2025

Choose a reason for hiding this comment

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

We have a constant LOG_FILE in the path util for this.

I tried but it seems like rename ignores it when I change. Maybe it wants a "raw" filename.

Copy link
Collaborator

Choose a reason for hiding this comment

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

With const auto CurrentLog = LogDir / LOG_FILE; right? There shouldn't be any difference since it's just a string macro.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, you were right it works.

Choose a reason for hiding this comment

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

Would it be more convenient if we defined the log file name without the extension? That way, we could easily change the base name in one place.

constexpr auto LOG_FILE = "shad_log";`

Then construct the full paths like this:

const auto CurrentLog = LogDir / (std::string(LOG_FILE) + ".txt");
const auto NewLogName = LogDir / (std::string(LOG_FILE) + ".old.txt");

What do you think about this approach?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Would it be more convenient if we defined the log file name without the extension? That way, we could easily change the base name in one place.

constexpr auto LOG_FILE = "shad_log";`

Then construct the full paths like this:

const auto CurrentLog = LogDir / (std::string(LOG_FILE) + ".txt");
const auto NewLogName = LogDir / (std::string(LOG_FILE) + ".old.txt");

What do you think about this approach?

The problem is that LOG_FILE is shad_log.txt, if we do what you showed, it would make shad_log.txt.txt and shad_log.txt.old.txt

Choose a reason for hiding this comment

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

Yes, now I see that the constant is already used in the code. My bad.

@Xphalnos
Copy link
Collaborator Author

@squidbus I placed the code to rename the log outside the emulator init. Is it ok now?

@squidbus
Copy link
Collaborator

I placed the code to rename the log outside the emulator init. Is it ok now?

What I had more in mind was, inside the log system where we initialize the file output to shad_log.txt, insert the rename of the previous log before that. But it's not something I feel particularly strongly about, just a suggestion.

@Xphalnos
Copy link
Collaborator Author

I placed the code to rename the log outside the emulator init. Is it ok now?

What I had more in mind was, inside the log system where we initialize the file output to shad_log.txt, insert the rename of the previous log before that. But it's not something I feel particularly strongly about, just a suggestion.

Tell me if I should migrate it to the log system.

@gandalfthewhite19890404

Compressing was planned? Logs may be VERY BIG.

@Xphalnos
Copy link
Collaborator Author

Compressing was planned? Logs may be VERY BIG.

Probably later but it requires a lot of extra work.

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.

4 participants