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

log: change comptime log to .debug and add runtime filtering #2539

Merged
merged 1 commit into from
Dec 5, 2024

Conversation

cb22
Copy link
Contributor

@cb22 cb22 commented Dec 4, 2024

Previously, .debug log messages were filtered out at comptime. While nice from a binary size and performance (more on that later) point of view, this meant that a user couldn't specify --log-debug or similar and would need a new binary to get debug logging.

Make it so that we do runtime log filtering instead. The performance penalty for this was negligible in testing; both microbenchmarks and the actual benchmark.

The one downside is binary bloat: this increases the size of a release build by ~300KiB.

To use, specify --log-debug --experimental on the CLI when starting a replica. --log-debug instead of --log=... because I feel we don't want to allow levels quieter than .info in any case.

It's currently only supported for start. Scaffolding for clients is there too, with filtering of the messages before they cross FFI and requiring an additional flag to be set. Actually setting this flag from any client libraries is still unimplemented - but this makes it no harder than before to change client logging (edit code & recompile).

Things like the VOPR and fuzzers use their own way of setting logging, and are unaffected.

Copy link
Member

@matklad matklad left a comment

Choose a reason for hiding this comment

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

<3!

// Other messages are silently dropped if no logging callback is specified - unless they're
// warn or err. The value in having those for debugging is too high to silence them, even
// until client libraries catch up and implement a callback handler.
const callback = if (message_level == .debug and logging.debug)
Copy link
Member

Choose a reason for hiding this comment

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

meant to say

Suggested change
const callback = if (message_level == .debug and logging.debug)
const callback = if (message_level == .debug and !logging.debug)

perhaps?

Could you also separate out this if to be a distinct statement? Right now, the if is quite busy and feels like it handles separate concerns?

Maybe avoid the ternary at all?

if (message_level == .debug and !logging.debug) {
    return;
}

if (logging.callback == null and 
      (message_level == .warn or message_level === .err)) {
  std.log.defaultLog(message_level, scope, format, args);
  return;
}

const callback = logging.callback orelse return;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Whoops! Good catch.

Yeah agreed, I thought originally there might be a tiny performance benefit from a ternary, but I'm probably wrong and client logging is called way less than replica logging so it's less relevant too.

Previously, .debug log messages were filtered out at comptime. While nice
from a binary size and performance (more on that later) point of view,
this meant that a user couldn't specify `--log-debug` or similar and would
need a new binary to get debug logging.

Make it so that we do runtime log filtering instead. The performance
penalty for this was negligible in testing; both microbenchmarks and the
actual benchmark.

The one downside is binary bloat: this increases the size of a release
build by ~300KiB.

To use, specify `--log-debug --experimental` on the CLI when starting
a replica.

It's currently only supported for `start`. Scaffolding for clients is there
too, with filtering of the messages before they cross FFI and requiring
an additional flag to be set. Actually setting this flag from any client
libraries is still unimplemented - but this makes it no harder than
before to change client logging (edit code & recompile).
@cb22 cb22 added this pull request to the merge queue Dec 5, 2024
Merged via the queue into main with commit 831d0a4 Dec 5, 2024
38 checks passed
@cb22 cb22 deleted the cb22/debug-logs branch December 5, 2024 18:45
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.

2 participants