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

Add tracing for logging #93

Merged
merged 2 commits into from
Dec 19, 2024
Merged

Conversation

caspark
Copy link
Contributor

@caspark caspark commented Dec 15, 2024

Closes #89.

I already had 90% of this implemented on my ggrs fork so I figured I'd just push it up and see if you were happy to go with tracing as the log choice. (If you prefer using log's API instead, I'm happy to rework this to do that instead.)

Summary of changes:

  • Add tracing dependency to library, and tracing_subscriber + tracing_log for dev deps so we can use them in examples and have all logs going to one place. (Importantly, we need to use tracing_log and turn on macroquad's log_rs feature to ensure that macroquad's logs - which includes our info!/etc logs because we import macroquad's prelude - get routed to tracing)
  • Fix the specific cases mentioned in Add a logging framework #89 :
    • Fix the println in advance_frame()
    • Don't panic in debug mode on large UDP packet sizes anymore - just warn!() instead (in both debug and release mode)
    • Warn when sparse saving is enabled in lockstep mode
  • Add various logging calls that I found useful in my own dev work on ggrs - most notably, trace logging for all network traffic has been really useful.
  • Add custom debug impl for Input that prints the Input's bytes in hex, so that Input messages are a tiny bit more understandable

Also includes one tiny non-logging change of an error message format (will call it out in a separate comment).

return Err(GgrsError::NotSynchronized);
}

// check if input for all local players is queued
for handle in self.player_reg.local_player_handles() {
if !self.local_inputs.contains_key(&handle) {
return Err(GgrsError::InvalidRequest {
info: "Missing local input while calling advance_frame().".to_owned(),
info: format!(
"Missing local input for handle {handle} while calling advance_frame()."
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here's the non-logging change: when the user didn't provide input for a handle, include the handle with missing input in the error message. I suppose technically it's a breaking change, but it would be super, super surprising if anyone was actually relying on parsing the error messages. (If anyone does complain, we can fix it by adding dedicated error types for each possible error instead.)

Anyway, this is totally not logging related, but still kind of matching the theme of improving debuggability of this library. Still, let me know if you want me to split it out into its own trivial PR for the sake of having PRs be single-purpose.

Copy link
Owner

Choose a reason for hiding this comment

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

We're still 0.x, lets break the API :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, as a Rust codebase, we are officially not allowed to ever release version 1.0 ;)

(sure, sounds good)

@caspark caspark force-pushed the add-tracing-for-logging branch from ec6cc7e to 6188763 Compare December 18, 2024 06:35
@gschup gschup merged commit e57f73a into gschup:main Dec 19, 2024
2 checks passed
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.

Add a logging framework
2 participants