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

Disable logging on startup #25

Open
Discostoff opened this issue Jan 20, 2025 · 5 comments
Open

Disable logging on startup #25

Discostoff opened this issue Jan 20, 2025 · 5 comments

Comments

@Discostoff
Copy link

Hello,

is it possible to remove the logging on app startup?

@Kir-Antipov
Copy link
Owner

Hi, and apologies for the late response!

I assume you're referring to MonoMod's logging, because HotAvalonia itself doesn't log that much (in fact, it logs too little, which is something worth improving on my side). While I agree that MonoMod's logging in this context is quite excessive, does it cause any actual issues for you, or is it more of a matter of taste? I could look into disabling it for the next release.

For now, you can completely disable the MonoMod path by setting the HOTAVALONIA_DISABLE_INJECTIONS environment variable to true when launching your app. Keep in mind, though, that this will somewhat limit HotAvalonia's hot reload capabilities.

@Discostoff
Copy link
Author

Iam not sure, but startup time feels longer. is this correct? Environment.SetEnvironmentVariable("HOTAVALONIA_DISABLE_INJECTIONS", "1");

@Kir-Antipov
Copy link
Owner

Iam not sure, but startup time feels longer. is this correct?

You are 100% correct. However, it's hardly because of logging; it's just MonoMod being MonoMod - it's a fully featured .NET injection engine, which is usually used for modding games, and it takes its sweet time to initialize everything it needs.

I don't actually need injections for much. As you can see, HotAvalonia kinda functions even without those. Thus, I implemented the HotAvalonia.Fody package, which performs the minimal weaving required for full hot reload support during compilation. However, it's a little bit cumbersome to set up at the moment, so you may want to wait for v3, where I plan to drastically simplify the installation process as a whole, allowing you to easily opt out of MonoMod usage with a simple setting like <HotAvaloniaUseInjections>false</HotAvaloniaUseInjections> in your project file.

Environment.SetEnvironmentVariable("HOTAVALONIA_DISABLE_INJECTIONS", "1");

Yup, that should do the trick. Just make sure to call it before HotAvalonia begins its initialization; otherwise, it will be too late. If you're launching your app from VSC, you can set the environment variable directly in launch.json, like I do here (just change false to true in your case).

@Discostoff
Copy link
Author

Thank you for your work, it saves a lot of time working with avalonia.
HOTAVALONIA_DISABLE_INJECTIONS does the trick for me.
I dont see anything missing, everything is updating during runtime.

@Kir-Antipov
Copy link
Owner

Thank you so much! It's always nice to hear that my work has helped somebody! :3

Also, I underestimated how slow logging (and string concatenation in general) can be. You were absolutely right - the startup time does take a significant hit due to the debug log spam. If I disable it:

object? logger = Type.GetType("MonoMod.Logs.DebugLog, MonoMod.Utils").GetStaticField("Instance")?.GetValue(null);
logger?.GetType().GetInstanceField("globalFilter")?.SetValue(logger, 0);

The demo app starts booting much, much faster, even when using MonoMod injections. So, yeah, I'll definitely include this in the next version, as MonoMod logs provide little to no value for HotAvalonia users and only slow down the startup process.

Thanks for bringing this to my attention!

Kir-Antipov added a commit that referenced this issue Feb 16, 2025
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

No branches or pull requests

2 participants