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.

Use SLF4J for library logging.

See original GitHub issue

Logging in Feign today is managed entirely behind our Logger abstraction. This wrapper is a simplistic form of logging facade similar to Commons Logging and SLF4J.

We should consider adopting a logging facade and replace the Logger with a more distinct LogConfiguration or other such abstraction. This change will allow users to control with logging subsystem they want to use without the need to configure Feign separately.

This will allow us to use the logger facade instances throughout the library, increasing our ability to log additional internal details while removing our current requirement to implement logger implementation specific Logger instances.

Here is an example of what the resulting changes to Feign.Builder could look like:

Feign.builder()
   .log(LogConfiguration.Builder()
      .withRequest()
      .withResponse()
      .withHeaders()
      .build())
   .build();

In addition, configuring what information is logged during Feign operations will become more explicit, leading to increased understanding and ease of use.

The potential draw backs here are that whatever facade we choose will require users to include that dependency in their project and we will need to include documentation on how to manage conflicts with Commons Logging for users whose projects intersect/conflict. This information is readily available however and shouldn’t be considered a major blocker to this approach.


The alternative is to adopt something similar to what Spring has done, which is to maintain the Logger abstraction and place ourselves in the middle, co-opting the detection of the logging framework and adapt accordingly. More information can be found here: https://github.com/spring-projects/spring-framework/issues/19081

While this does provide the most flexibility, it does mean that we will be explicitly choosing Commons Logging over SLF4J as SLF4J is more opinionated and expresses that users will need to configure SLF4J and the appropriate bridges. Also, it does require that we, the Feign maintainers, also maintain our own mini-facade. For this reason alone, I feel that the above suggestion of using SLF4J and adding it as a dependency, it worthwhile.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
velocommented, Dec 22, 2021

Do you wanna play around with logs + capabilities and make a proposal? May or may not be approved, but, could be nice

0reactions
velocommented, Mar 21, 2022

sounds awesome

Read more comments on GitHub >

github_iconTop Results From Across the Web

SLF4J in distributable library, how to obtain Logger
SLF4J is composed of two parts. First the API which you use in your lib to code your logging calls. And secondly the...
Read more >
SLF4J Manual
The Simple Logging Facade for Java (SLF4J) serves as a simple facade or abstraction for various logging frameworks, such as java.util.logging, logback and ......
Read more >
Introduction to SLF4J - Baeldung
Simple Logging Facade for Java (abbreviated SLF4J) acts as a facade for different logging frameworks (e.g., java.util.logging, logback, ...
Read more >
SLF4J Tutorial: Configuration Example for Logging in Java
We create the Logger instance by using the LoggerFactory class and its getLogger method and providing the name of the class. That way...
Read more >
SLF4J: 10 Reasons Why You Should Be Using It - Stackify
This is the main purpose of SLF4J (Simple Logging Facade for Java) – a logging abstraction which helps to decouple your application from...
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