Dont' surface our LibLog implementation to consumers of Brighter
Our use of LibLog predates some useful ideas on how to control 'bleed' of a project's logger out into the consumer better. For example, we compile LibLog as public, so a consumer can grab our copy of the LibLog definition. This has value to us as a core library, with our own set of projects able to share our definition, but risks bleeding out to consumers.
One particular issue raised is that because we set a base logger on RequestHandler
What do we want to achieve:
1: Independence of any logging framework: client decides 2: Core library paramore.brighter.commandprocessor shares its definition with consumers 3: Customer sets logger, we use 4: We also wish to remain backwards compatible with existing clients. Our RequestHandler constructor that takes an ILog probably has to remain for the immediate future, even if we decide to make it obsolete. 5: Allow a client to control the level of our logging separately from the level of their logging. In other words let them control the namespace of the logger.
Suggested approach:
1: Provide a default constructor on RequestHandler that uses GetLogger to grab the current logger. 2: Provide the optional, but obsolete constructor that takes a logger for backwards compatibility. 2: In our builder call SetLogger against the Logger passed into the builder. This means the client only needs to worry about passing the logger into our builder not the Set/Get semantics
This would seem to move us on most positively. We can slate for some future release the option of removing the base class version of RequestHandler that takes an ILog.
I'm uncertain about all projects including LibLog or making Internals Visible to other assemblies (too broad as it pulls across all internals) as yet. But that can be a struggle for another day.
How does a consumer control filtering level of messages output by Brighter? E.g. "Here is my logger but I only want you to log ERROR and WARN". Do we leave this up to them to implement - to separate message filtering based on the originator?
.. he says hoping that makes sense
@ianbattersby Yes, it's controlled by the underlying logging framework that we hook into via LibLog. The most significant issue I guess, is to how that framework lets them control that, and does Brighter work well with the control to let them turn up or down our noise
Good news - much of this is trivial:
- a new ctor to RequestHandler
- call current ctor with LogProvider.GetCurrentClassLogger()
- obsolete current ctor
the only issue remaining is setting the log provider from the builder (Assum: CommandProcessorBuilder) as I think we need to add an override for ILogProvider as the signature of set is: LogProvider.SetCurrentLogProvider(ILogProvider);
so we'd need an override that ensure we accept ILogProvider as well as ILog... any issues?
Also - I think I can cover a test with a custo m log provider to ensure the LogProvider specified in the CommandProcessorBuilder is used in all Handlers that are specified without a logger... if that makes sense. Is that worth it??
Have a test. Passes. It's certainly easier ;-)
Reopened. Injecting a logger into the builder is confusing because whilst that sets the logger on the CP, it doesn't set the logger on the RequestHandler. Because that now use GetCurrentClassLogger, it depends on the what LIbLog sets. If you override what you pass in to builder from that, it has not effect on the command handler, which may not be what you expect. Now you can solve this, use IoC to inject your logger as per now, but I think on reflection that is not easy to understand.
So I have ripped out the ability to set the logger on the builder. it now asks you to do the right thing but just picking up the ambient logger.
I've pushed this down the stack.Everything that takes an ILog now has an overloaded constructor that just grabs CurrentClassLogger.
I've pushed through the examples, and it's simpler.
To avoid this being too painful, I'm leaving the override, so you don't have to rewrite your loggers.
I will change the documentation, and I may try to change the tests. The more you read the code and just see examples using the default constructors, the better I think.
OK here is what we have now:
1: Where we want to log we have two constuctors. A constructor that directly takes an iLog that you provide either directly or via your ioC container; a constructor that defaults that to LogProvider.GetCurrentClassLogger. 2: In Production code you should set up your log provider and use the constructors that do not take an ILog reference. 3: In Test code you should inject the ILog using a fake logger. We don't recommend testing log output, its an implementation detail, unless its an important part of your acceptance criteria for that behaviour.
This means that your production code should not need to take a direct dependency on Paramore's ILog implementation.
This still needs documentation, then I'll close this issue.