question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Expose the logger in the watcher constructor

See original GitHub issue

I’d like to propose a change to the public API which makes the library more fitting for applications that do not use global mutable loggers.

In my case, I use directory-watcher in Bloop. Our application uses Nailgun under the hood, and its architecture forces us to avoid global mutable loggers (i.e. neither logback nor log4j), and have a strict control over stdout and stderr. As a result, Bloop has its own slf4j-compliant logger which are immutable and local, and so we create them per client.

This architecture is a little bit at odds with the current implementation of the library, which has a static, global logger in DirectoryWatcher. My suggestion is that we remove it and make DirectoryWatcher.create take the logger as a parameter, so that users are in control of the situation.

I took myself the liberty of implementing this at https://github.com/jvican/directory-watcher/commit/a1c0e21c92032863480b16a696eb59ce4b29b822, and I released it under my own organization so that I can directly depend on it (0.5.2-a1c0e21c) – so there’s no rush to get this merged on my side.

I open this ticket to raise some discussion. If we agree on this change, I’ll open up a pull request. I believe my prototype can be massaged to avoid breaking changes downstream by duplicating all the create constructors to take a logger parameter, and those which don’t (the current interface) would directly fallback on the previous logger implementation via Logger.getLogger.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
gmethvincommented, Aug 21, 2018

@olafurpg @jvican Working on this in #18.

1reaction
jvicancommented, Apr 11, 2018

I think the change you’re suggesting is fine as long as we have overloaded versions that don’t require the logger parameter. If logger is not passed it can default to Logger.getLogger(getClass()). This way the change is fully backwards compatible, and we keep the more convenient APIs for users who don’t care about the logger.

Great, that’s exactly what I describe in my last paragraph. I’ll try to make a pull request with this change soon.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ExecutableAction (core 7.10.0 API)
Nested Class Summary. Nested classes/interfaces inherited from interface org.elasticsearch.common. · Field Summary. Fields. Modifier and Type, Field · Constructor ...
Read more >
Logger (Apache Log4j Core 2.12.1 API) - Apache Logging Services
This method is not exposed through the public API and is used primarily for unit testing. void, addFilter(Filter filter). This method is not...
Read more >
Logger (Java Platform SE 7 ) - Oracle Help Center
A Logger object is used to log messages for a specific system or application component. Loggers are normally named ... Modifier, Constructor and...
Read more >
reconciler package - github.com/google/knative-gcp/pkg/reconciler ...
These constructors will: Construct the Reconciler,; Construct a controller.Impl with that Reconciler,; Wire the assorted informers this Reconciler watches to ...
Read more >
Should logging infrastructure be injected when using IoC/DI if ...
I am wondering if logging DI is necessary when using logging facade? I understand that explicitly exposing dependencies via constructor ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found