-
Notifications
You must be signed in to change notification settings - Fork 439
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: switch from log4j to SLF4J #610
Conversation
@sullis We recently added |
Hi @eshanholtz, below I've written up a few reasons for using Slf4j. Log4j is an implementation, Slf4j is a logging abstraction and not an actual implementation. This is important, as it allows consumers of your library to choose their own flavor of logging implementation. By forcing Log4j unto your consumers,
To hit it home further, I'm currently running into one of these problems. The Twilio SDK is currently conflicting with server frameworks such as Spring and Micronaut that rely on classpath scanning and detect which logging library is on the classpath. See for example here where Micronaut detects the logging implementation, however, when it finds multiple Logging implementations it will refuse to start (as it should). Spring works in a similar fashion. I believe it's considered a rule of thumb that as SDK developers you must use Slf4j and leave logging implementation choices to your consumer. SDK developers can chose to include log4j as runtime dependency when they develop, but it should never become a compile time dependency. Slf4j is exactly created to solve these type of problems. My $.02. |
As FYI, for whoever is running into similar issues, Twilio 7.3.0 is the latest release before log4j became a compile dependency. Reverting back to Twilio SDK 7.3.0 worked for me. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR @sullis!
Please take a look at my comments and let us know what you think. Thanks again!
README.md
Outdated
Twilio.setLoggerConfiguration("path/to/log4j2.xml"); | ||
``` | ||
|
||
This library uses SFL4J for logging. Consult the SFL4J documentation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to update the example (perhaps java.util.logging, logback or log4j).
309da69
to
3032865
Compare
This is a proof of concept. It demonstrates how SLF4J could be used as the Logging API. SFL4J is the standard logging API for open source Java libraries.
3032865
to
15271f9
Compare
@sullis Your changes look good. Can you just address the last few comments from @thinkingserious and we can get this PR merged. Thanks! |
Hello @sullis, Would you like us to take this PR from here and get this PR closed out? Please let me know what you think. Thanks again! With best regards, Elmer |
Please take ownership of this PR and/or open a replacement PR. I think it is best for you to own it. |
Thank you @sullis! We appreciate your contribution to help us get this update merged! |
Here is how I tested this, from this branch:
import com.twilio.Twilio;
import com.twilio.rest.api.v2010.account.Message;
import com.twilio.type.PhoneNumber;
public class LogExample {
public static void main(String[] args) {
String accountSid = System.getenv("TWILIO_ACCOUNT_SID");
String authToken = System.getenv("TWILIO_AUTH_TOKEN");
Twilio.init(accountSid, authToken);
Message message = Message.creator(
new PhoneNumber(System.getenv("TWILIO_TO_NUMBER");),
new PhoneNumber(System.getenv("TWILIO_FROM_NUMBER");),
"Hello logging world!"
).create();
System.out.println(message.getSid());
}
}
Then, you should see something like:
|
@@ -59,11 +58,14 @@ public Response request(final Request request) { | |||
|
|||
logRequest(request); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to add a check either within this function or before this function is called to make sure logger.isDebugEnabled()
. Within the logRequest()
function can we add some additional logic to make sure headerParams and queryParams are not null before we log them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great catch! isEmpty()
does not catch null values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you test this with Java 9 or later to make sure that we don't see any issues with the build artifact?
I tested with Java 11 and did not observe any issues. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎆
Checklist