Skip to content

Replace Common.Logging with LibLog - #42

Closed
derwasp wants to merge 1 commit into
launchdarkly:masterfrom
albumprinter:feature/replace-common-logging-with-liblog
Closed

derwasp wants to merge 1 commit into
launchdarkly:masterfrom
albumprinter:feature/replace-common-logging-with-liblog

Conversation

@derwasp

@derwasp derwasp commented Oct 9, 2018 •

Copy link
Copy Markdown

Warning: this change is not backwards compatible

Why did I create this PR?

At albelli we were using LaunchDarkly.Client of version 3.3.2, which doesn't depend on Common.Logging. Our application however does depend on it, but on a very old version, namely 2.2.0.
We are also using log4net and a Common.Logging connector (note the old version number), which was not as restrictive as the new version. Due to legacy reasons, we have a bunch of different packages with slightly different versions of log4net. Assembly redirects solved the problem most of the time. But since your package depends on the new version of Common.Logging (and it should, since .NET core), the aforementioned connector should also be updated. But it requires only a specific log4net version.
All that results in us being unable to run our application if we update the SDK version.

What does this PR do exactly?

Since Common.Logging is a quite an old framework, which is not very actively maintained nowadays, I suggest to use LibLog instead. It doesn't generate any additional dependencies, since it's installed as a source file.
The new version also has fancy installation way, but it doesn't support netstandard < 2.0, so I am installing it "the old way": by just copying the file in the source directory.

If you would consider dropping support for netstandard1.x, this file can be skipped and the PR would be more concise.

I already emailed your support team about that. But since we don't have a lot of time left, I decided that I might as well do a PR upfront.

@derwasp

derwasp commented Oct 10, 2018 •

Copy link
Copy Markdown
Author

One issue I see so far: 3 projects depend on common logging. And the dependency between the projects looks like this: EventSource <- Common <- Client
In order to use LibLog, we can:
a) Add it to the bottom most library (EventSource in this case) and utilize InternalsVisibleToAttribute to give other libraries access to LogProvider.For<T>() by using LIBLOG_PUBLIC. See docu for details. But EventSource library doesn't look like a "common" library to me.
b) We can add LibLog per library. (Which is kind of what this PR starts, since LIBLOG_PUBLIC is not defined here.) This implies though if you have any custom logging providers you want to register, you would have to do it per library. Automatic logger discovery will still work anyway.
c) We can create a LaunchDarkly.Logging library which would only contain a LibLog.cs and InternalsVisibleToAttribute for the other libraries. Something similar to what we have in our CorrelationTracking library. (but we are not using InternalsVisibleToAttribute.)

In any case, waiting for your feedback on this.

@derwasp

derwasp commented Oct 10, 2018

Copy link
Copy Markdown
Author

btw, I see that you actually used Microsoft.Extensions.Logging before.
What was the reason behind this PR?
#22

@eli-darkly

Copy link
Copy Markdown
Contributor

btw, I see that you actually used Microsoft.Extensions.Logging before.
What was the reason behind this PR?

The reason for the change was briefly described in issue #78.

@eli-darkly

Copy link
Copy Markdown
Contributor

One issue I see so far: 3 projects depend on common logging.

It's actually 4 - there's also our beta Xamarin client. This is a big concern I would have about putting in a new logging framework that's not actually shared between assemblies: if there is any significant change in it, then we would have to re-release all of those things, rather than just upgrading one dependency at the application level.

The other concern is of course just that this could require all our customers to once again change how their projects are set up. Although I'm not entirely sure what would happen if you took a project that currently had, say, Log4Net and Common.Logging, and then changed the library to use LibLog - would it just continue to work because it would auto-detect Log4Net?

In any case, I think this is something that will require more thought and we will probably also want to survey other developers in our community. The goal is to provide something that will work for, ideally, everyone.

@derwasp

derwasp commented Oct 15, 2018

Copy link
Copy Markdown
Author

This is a big concern I would have about putting in a new logging framework that's not actually shared between assemblies

If you would like to have a shared logging framework, you can go for the option c) (create a LaunchDarkly.Logging library). This way you would have full control of the logging and how you want to have it.

There should be no changes to this library ( in theory ;) ). Because the main thing that LibLog does is provides a way to hook up your own logging framework in the library and doesn't do any logging by itself.

would it just continue to work because it would auto-detect Log4Net?

Yes, it should automatically detect log4net or other frameworks that it supports. It just tries to find a type in the current app domain.

Warning: this change is not backwards compatible
@eli-darkly

Copy link
Copy Markdown
Contributor

I'm not sure what a LaunchDarkly.Logging library would accomplish since then we would either have to write connectors for it ourselves, or make our users write connectors, to support the existing logging frameworks that people are actually using.

As for "there should be no changes to this library" (LibLog), I am skeptical. If there is any change in the API of any of the logging frameworks that it supports, I don't see how it would be possible to avoid having to update it. It seems to me like very much the same issue as keeping the Common.Logging connectors up to date, except that it would be baked into our library code.

@derwasp

derwasp commented Oct 16, 2018

Copy link
Copy Markdown
Author

Let me start by quoting Damian Hickey, the author of LibLog here:

LibLog is designed specifically and primarily for library developers that want to provide logging capabilities.

This has been typically achieved in one of three ways:

  1. Take a hard dependency on a logging framework. Thus forcing all consumers of your library to also take a dependency on your choice of logging framework. This causes issues when they want to use a different framework or are using a different version of the same one.
  2. Use Common.Logging. Providing an abstraction over all the other frameworks has merit but it will add a reference to your consumers' projects. It's still a versionable dependency and can be prone to versioning clashes with other libraries. Common.Logging's ILog contains ~65 members whereas LibLog's ILog has just single method making it easier to implement custom loggers.
  3. Define your own Logging abstraction. A common approach used by many libraries that don't want to do 1 or 2. LibLog is designed to help those that would otherwise go down this path.

So, the issue we have is the exact one that is described by Damian in 2.. Since the library is not supposed to write logs, but just have an option to connect any kind of logger, an interface is a way to solve this. LibLog provides exactly this interface.
It also has a buch of connectors to the different logging frameworks. But these should be considered supplementary, a nice addition to the basic interface. Because for sure not all the frameworks are available there. But when a new framework should be connected to our library (LaunchDarkly Client in this case), the end consumer can just implement a very simple interface and everything will work. See DebugLogProvider in my PR.

Also, in case an API of a specific logging library changes, I will quote Damian:

Even though the APIs of the various loggers have been very stable over time, if they do change your library will fail gracefully. If (when!) that happens, users of your library can call LogProvider.SetCurrentLogProvider() to get things working again.

@eli-darkly

Copy link
Copy Markdown
Contributor

Am I correct that in your implementation, if you are using the LaunchDarkly SDK and want to specify a custom logging provider, you would have to specify it individually for each of the (3) assemblies in the SDK? If so, that is a problem as we really don't want people to have to worry about the exact internal structure of the project.

@derwasp

derwasp commented Oct 17, 2018

Copy link
Copy Markdown
Author

In this exact PR, yes. That is why I mentioned the option c), in which a custom base logger package would be created and used for all the LaunchDarkly libraries. And customers would be able to hook into it.
To give other libraries access to it you have 2 options:

  1. Use InternalsVisibleToAttribute
  2. Set LIBLOG_PUBLIC

Please see my first comment for more details and links

@derwasp derwasp closed this Aug 26, 2020
tanderson-ld added a commit that referenced this pull request Aug 6, 2026
Wires the contract-tests service added earlier in this PR into CI so
we actually validate LaunchDarkly.EventSource's SSE behavior against the
sse-contract-tests harness on every push. Without this step the test
service was inert -- the code existed but nothing ran the harness against
it.

Follows the pattern used by launchdarkly/eventsource (Go) and
launchdarkly/okhttp-eventsource (Java): a Makefile at repo root with
build-contract-tests / start-contract-test-service-bg / contract-tests
targets, plus a GitHub Actions job that uses the shared
launchdarkly/gh-actions/actions/contract-tests action to download and
run a released harness (VERSION=v2, currently resolves to v2.31.0).

Once the payload-size-stress-testable capability (defined in
sse-contract-tests PR #42) lands in a released v2.x, this job will
automatically pick up the sweep on its next run -- no additional CI
changes needed.

The extra_params skips four pre-existing dotnet-eventsource behavioral
gaps unrelated to SDK-2755: null-byte ID handling, CR-only line
terminator parsing, CRLF-split-across-chunks handling, and
partial-message ID carry-over on reconnect. Filed a follow-up ticket to
survey and fix these; once fixed, remove the corresponding --skip.
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