-
Notifications
You must be signed in to change notification settings - Fork 797
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
Only case sensitive check for minimumLevel override #1944
Comments
changed the levelSwitch check from case sensitive namespace checks to a case insensitve check Refs: serilog#1944 Signed-off-by: Phil Schneider <info@philschneider.de>
change string comparison culture from currentCulture to Ordinal Refs: serilog#1944
Duplicate #1335 - would still love to see a case-insensitive match. |
Somewhat related - serilog/serilog-settings-configuration#386 found that the parser for the log level enum in configuration was inconsistently case-sensitive and case-insensitive, and that got resolved to be case-insensitive everywhere. That makes things just slightly more inconsistent: enum parsing is case-insensitive, but the keys are case-sensitive. |
Why can't this be a 'flag' ? Give the developer the option? |
Does anyone have comparative perf numbers for performing the level check in case-insensitive vs sensitive mode? I think that's the place we're most likely to hit issues. I don't think it's a matter of preference, I'd guess (almost?) everyone would be fine with insensitive matches if they performed identically, so keen to steer clear of flags/options at this stage. v4 is open now, so a good time to look at this if we think it's got a chance :) |
Was going to look at this, just coming up with some simple benchmarks, but wanted to verify I'm benchmarking the right thing. It appears the case-sensitivity comes in when checking if there is a level override for a particular context. So that means If I'm not mistaken, that boils down to just determining the difference in perf between
Does that sound right? Is there some other string comparison or larger path that needs to be benchmarked? Would benchmarks simply comparing those two methods be enough to inform a decision? |
Thanks for the follow-up @tillig. I think there's a bug in the current version, that It would be good to know the difference in raw perf across those four variants; I think we'd still want to know what the difference is in the context of logging with a suppressed override, e.g.: var log = new LoggerConfiguration()
.MinimumLevel.Override("Microsoft.AspNetCore.Hosting", LogEventLevel.Warning)
.CreateLogger();
var scoped = log.ForContext("Microsoft.AspNetCore.Hosting");
// Bench this bit:
scoped.Information("Hello"); Perf will vary based on the number of overrides, so there would still be some extrapolation to do, but if there's no significant difference we'd be good-to-go. |
Oh, looks like there's already a nice benchmark set up for source context matching, so I can add to that. |
Hmmm. I'm going to have to work this one out. Having trouble with BenchmarkDotNet.
Trying to run that, I get a bunch of errors about how the autogenerated benchmark assembly is tareting netcoreapp2.1 and that there's a security vulnerability in
That causes the benchmark to fail to compile and run. I may need to change this to use the BenchmarkSwitcher in my branch. |
Oh, I see why this is. It's the |
Rather than stick the
Things to notice:
If my logic is sound, that basically means it's a question of whether case-insensitivity is worth a 2ns hit per level lookup. My opinion is that it's a pretty negligible hit to make this consistent across config and logging, but it is a microperf (nanoperf?) hit, so that may make a difference. Let me know if I should still look at benchmarks for just the string methods. |
Awesome, thanks for doing this @tillig. It's a bit tricky to draw precise conclusions from the benchmark because it mixes results from a variety of cases (some where the logger triggers an override immediately - which bails out of the check early - some where it doesn't, or will trigger further down the list). It thus might be that the ~20ns you mention is attributable to one or two of the cases, and not across the board. Just making a note of this, and thinking we might want to tweak the benchmark in the future, but at first glance the difference isn't enough to rule out the change 👍 There's also the possibility that we might be able to improve the performance of the level override map with some other tricks, such as computing a pre-filter based on the first character or two from the context name. E.g. if my overrides are I wouldn't suggest trying to roll this into the case-insensitivity PR, but could be worth keeping up our sleeves. |
Description
Serilog currently only supports case sensitive matches when overriding the log level for a specific namespace, when for example using Serilog with Serilog.Settings.Configuration and setting env variables for a docker image the Namespaces can't be all upper case.
Reproduction
Setting up a test project with Serilog and Serilog.Settings.Configuration installed, configure Serilog for example like this:
add a appsettings file with the following configuration:
Then execute the application with the following env var: SERILOG__MINIMUMLEVEL__OVERRIDE__TEST.NMSPC=Debug
The minimum logLevel for Loggers within that namespace will be Information
If needed I can provide an example repo.
Expected behavior
The minimum log level for logger instances creates within the Test.Nmspc Namespace should be Debug.
Relevant package, tooling and runtime versions
Additional context
I've already provided a PR with a change for the case insensitive check.
The text was updated successfully, but these errors were encountered: