Skip to content

Conversation

tsimbalar
Copy link
Member

What issue does this PR address?
Related to #967
This is a second PR after comments on #1027 and discussion in #1032

The idea is that we no longer try to support MinimumLevel.Override in sub-loggers, but write to the SelfLog that it is not supported nor recommended, and using .Filter is better, or event better, the overrides of the root logger.

Does this PR introduce a breaking change?
No, it actually just makes it explicit that MinimumLevel.Override is not supported on sub-loggers

Please check if the PR fulfills these requirements

  • The commit follows our guidelines
  • Unit Tests for the changes have been added (for bug fixes / features)

Other information:
I'm not super convinced about the message written to SelfLog :) Review from a native English speaker would be nice :)

@tsimbalar tsimbalar force-pushed the 967-no-sublogger-overrides branch from 2db825e to e2125d6 Compare September 28, 2017 19:25
@tsimbalar tsimbalar changed the title 967 no sublogger overrides Make it clear that Sub-logger MinimumLevel.Override is not supported Sep 28, 2017
Copy link
Member

@nblumhardt nblumhardt left a comment

Choose a reason for hiding this comment

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

Sorry this took so long to get to! Overall, looks good, I think this is the right approach. Added some thoughts and nitpicks :-) Thanks!

"Overrides in a sub-logger are not supported and are therefore ignored. " +
"We recommend applying .MinimulLevel.Override on the root logger or " +
"using .Filter in your sub-loggers. " +
"Note that support for sub-loggers' minimum level overrides may be removed in the next major version.");
Copy link
Member

Choose a reason for hiding this comment

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

Reads very nicely 👍

We could probably cut it down a bit to just:

Minimum level overrides are not supported on sub-loggers and may be removed completely in a future version.

since it's googleable back to this issue :-) Happy to go with the longer version if you think it's preferable.

"Note that support for sub-loggers' minimum level overrides may be removed in the next major version.");
}

ILogEventSink secondaryLoggerSink = new SecondaryLoggerSink(subLogger, attemptDispose: true);
Copy link
Member

Choose a reason for hiding this comment

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

Can use var. Variable with the same purpose is called secondarySink in the method below.

return Sink(new SecondaryLoggerSink(logger, attemptDispose: false), restrictedToMinimumLevel);
ILogEventSink secondarySink = new SecondaryLoggerSink(logger, attemptDispose: false);

if (logger is Logger concreteLogger)
Copy link
Member

Choose a reason for hiding this comment

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

if (logger is Logger concreteLogger && concreteLogger.HasOverrideMap) ?

var subLogger = lc.CreateLogger();
if (subLogger.HasOverrideMap)
{
// Overrides in sub-loggers are not supported and will be ignored
Copy link
Member

Choose a reason for hiding this comment

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

The comment here is probably redundant, given the content of the message we are writing to SelfLog.

"Overrides in a sub-logger are not supported and are therefore ignored. " +
"We recommend applying .MinimulLevel.Override on the root logger or " +
"using .Filter in your sub-loggers. " +
"Note that support for sub-loggers' minimum level overrides may be removed in the next major version.");
Copy link
Member

Choose a reason for hiding this comment

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

Dropping the comment and using the shorter message would reduce the sense of duplication here.

@@ -69,6 +69,11 @@ void ApplyInheritedConfiguration(LoggerConfiguration child)
/// </remarks>
public LoggerAuditSinkConfiguration AuditTo => new LoggerAuditSinkConfiguration(this, s => _auditSinks.Add(s), ApplyInheritedConfiguration);

void AddOverride(string source, LoggingLevelSwitch levelSwitch)
Copy link
Member

Choose a reason for hiding this comment

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

I don't know that this method is as useful now given the change in direction; inlining the assignment in the next method can save us five lines.

Copy link
Member Author

Choose a reason for hiding this comment

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

yup, I'll put that back to its original state


namespace Serilog.Tests.Support
{
public class TemporarySelfLog : IDisposable
Copy link
Member

Choose a reason for hiding this comment

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

We've needed something like this for a while 👍

(A future version might modify this slightly to only siphon off messages for one logical call context/thread at a time, as this will have interleaving problems when we introduce more tests using it that might run in parallel.)

Copy link
Member Author

Choose a reason for hiding this comment

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

Not quite sure what that would look like... ThreadStatic comes to mind, but not sure that would help in that case.

@tsimbalar
Copy link
Member Author

Thanks for the review !
I'll make the changes, and probably rebase/squash this PR, because it's starting to contain lots of commits going in very different directions and the history would be confusing

Write a warning message to the SelfLog when using WriteTo.Logger() with a logger that has specified MinimumLevel overrides.
Related to issue serilog#967
Related to discussion serilog#1032
@tsimbalar tsimbalar force-pushed the 967-no-sublogger-overrides branch from e2125d6 to 48b4757 Compare October 9, 2017 05:43
@tsimbalar
Copy link
Member Author

@nblumhardt not sure what is going wrong with the Travis CI build https://travis-ci.org/serilog/serilog/builds/285388771
... something about expired signature keys somewhere , related to mongodb....
looks like I'm not the only one, see travis-ci/travis-ci#8554

@tsimbalar tsimbalar closed this Oct 9, 2017
@tsimbalar tsimbalar reopened this Oct 9, 2017
@tsimbalar
Copy link
Member Author

Closed and re-opened to trigger a new build

@nblumhardt
Copy link
Member

Looks great :-)

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