growthbook / growthbook-sdk-java

The Java SDK for GrowthBook (JVM, Android)
https://docs.growthbook.io/lib/java
MIT License
7 stars 10 forks source link

GH-26 The SDK should use a logging library #24

Closed igorlovich closed 1 year ago

igorlovich commented 1 year ago

As per GH-26, I have migrated all the System.out and .printStackTrace to logging calls.

I noticed there are a bunch of commented out println statements in the code; We may want to un-comment them and log them at .debug or .trace levels, depending on how you use them.

tinahollygb commented 1 year ago

These annotations look fairly magical. I understand they inject a logger at the field level, but how does this work? How does a user provide their own logger? What if a project doesn't use Slf4j and uses a different logger, how would they provide a logger? I don't see any new properties added to the GrowthBook constructor and builder so it's not clear how they would add a logger.

igorlovich commented 1 year ago

@Slf4j is a lombok annotation that, as you have noticed, creates the log field; so nothing to do with slf4j. This can be done manually, without lombok, private final Logger log = LoggerFactory.getLogger(HelloWorld.class);.

It is important to keep in mind that slf4j is NOT a logging framework. It is a facade that allows a project to use whatever framework they want. This especially key for library developers as, they do not know which logging solution this or that project uses.

So let's take an example where the project uses log4j2 as the logging framework. It would already have the log4j2 dependency and be configured as desired. When they add thegrowthbook-sdk-java dependency, and they want to see its logs, they would add the log4j-slf4j2-impl binding dependency and the logs would show up as per their configuration.

If the project was using logback, they would not even need to add any dependencies as logback implements the slf4j api directly.

As you can see, I have added the slf4j-simple as a test dependency. This binding just prints to stdout / stderror, so during test execution the log messages will be printed out to console, same as before.