Giter Site home page Giter Site logo

Comments (4)

clehene avatar clehene commented on August 31, 2024 1

@hagbard the original issue was about simplification (it is indeed complicated and confusing to figure out why flogger decides to go with JUL instead of slf4j).

Having to have system-backend is another complexity aspect. It's against intuition to require a dependency for the backend that you're trying to override.

To use flogger with logback I have to do the following voodoo

    <dependency>
      <groupId>com.google.flogger</groupId>
      <artifactId>flogger</artifactId>
    </dependency>
    <dependency>
      <groupId>com.google.flogger</groupId>
      <artifactId>flogger-system-backend</artifactId>
    </dependency>
    <dependency>
      <groupId>com.google.flogger</groupId>
      <artifactId>flogger-slf4j-backend</artifactId>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
    </dependency>
    <dependency>
      <groupId>ch.qos.logback</groupId>
      <artifactId>logback-classic</artifactId>
    </dependency>
    <dependency>
      <groupId>ch.qos.logback</groupId>
      <artifactId>logback-core</artifactId>
    </dependency>

Then make sure a system property is set

System.setProperty("flogger.backend_factory", "com.google.common.flogger.backend.slf4j.Slf4jBackendFactory#getInstance");

Then instantiate the logger

private static final FluentLogger logger = FluentLogger.forEnclosingClass();

from flogger.

hagbard avatar hagbard commented on August 31, 2024

I've avoided going with any "just find it on the classpath" approaches for several technical reasons. I tried it initially but ran into several issues in cases when more than one backend was present. It's also much slower to start if you need to search a really big classpath (Google has some very large class paths for its binaries).

The need for flogger-system-backend is just so there's a completely reliable fallback if the named backend doesn't exist. It could probably be removed but then the binary would have to throw an error if no backend was available.

The reason the backend and core library are split (rather than just being together in one library) is that the core library is Java6 source compatible and the current JDK backend uses Java7 features.

I hope this helps explain things.

from flogger.

hagbard avatar hagbard commented on August 31, 2024

I just remembered that one of the reasons we didn't do this was to have a consistent approach with Android, where the SPI style of approach just doesn't work, and reflection is very expensive.

from flogger.

medb avatar medb commented on August 31, 2024

FWIW, I ended up with copying com.google.common.flogger.backend.system.DefaultPlatform class in my project and overriding default logger in it:
https://github.com/GoogleCloudDataproc/hadoop-connectors/pull/310/files

It would be nice to have multiple flogger-<backend>-default artifacts that have a default static binding for different backends, e.g. flogger-log4j-default, etc.

from flogger.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.