-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
#618 - Add ability to name specific wiremock instance #2448
base: master
Are you sure you want to change the base?
#618 - Add ability to name specific wiremock instance #2448
Conversation
This is looking good so far but let's add add a test that checks the name is actually emitted in logs. Also, what might be interesting is to also have it affect the private final Logger log = LoggerFactory.getLogger(firstNonNull(serverName, "WireMock")); |
@@ -15,19 +15,25 @@ | |||
*/ | |||
package com.github.tomakehurst.wiremock.common; | |||
|
|||
import static org.apache.commons.lang3.ObjectUtils.firstNonNull; |
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.
Please use ParameterUtils#getFirstNonNull
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.
Incorporated
|
||
private final boolean verbose; | ||
|
||
public Slf4jNotifier(boolean verbose) { | ||
this.verbose = verbose; | ||
} | ||
|
||
public void updateLogger(final String serverName) { | ||
log = LoggerFactory.getLogger(getFirstNonNull(serverName, "WireMock")); |
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.
Suggest we do this in a constructor overload rather than mutating
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.
TBH I am not site about making the logger non-static for that purpose. Maybe there is API would could invoke against a static field? Concurrency is not a problem here
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.
done... incorporated.
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.
Looks good overall, requesting changes because of unverified lass cast, and I second @tomakehurst's note about the APIs though do not feel strongly about that
|
||
private final boolean verbose; | ||
|
||
public Slf4jNotifier(boolean verbose) { | ||
this.verbose = verbose; | ||
} | ||
|
||
public void updateLogger(final String serverName) { | ||
log = LoggerFactory.getLogger(getFirstNonNull(serverName, "WireMock")); |
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.
TBH I am not site about making the logger non-static for that purpose. Maybe there is API would could invoke against a static field? Concurrency is not a problem here
public WireMockConfiguration serverName(String serverName) { | ||
|
||
this.serverName = serverName; | ||
((Slf4jNotifier) notifier).updateLogger(serverName); |
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.
This unchecked cast impacts extensibility IMO. I suggest doing proper instanceof
verification
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.
done
…-to-name-specific-wiremock-instance
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.
Options#getServerName()
is still a breaking change, because there is no default implementation
https://docs.oracle.com/javase/tutorial/java/IandI/defaultmethods.html
incorporated |
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.
My comments are addressed
public void checkServerNameIsPrintedInLogs() { | ||
|
||
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); | ||
System.setOut(new PrintStream(byteArrayOutputStream)); |
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 un-set this in an @AfterEach block, otherwise it might suppress the output from other tests when running everything.
this.verbose = verbose; | ||
} | ||
|
||
public void setLogger(String loggerName) { |
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.
I still think we should try to get rid of this and make the logger final.
Added ability to name specific wiremock instance.
References
#618
Submitter checklist
#help-contributing
or a project-specific channel like#wiremock-java