-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: extend logging for happy cases (#66)
<!-- Please describe your pull request here. --> ## References #65 <!-- References to relevant GitHub issues and pull requests, esp. upstream and downstream changes --> ## Submitter checklist - [ ] Recommended: Join [WireMock Slack](https://slack.wiremock.org/) to get any help in `#help-contributing` or a project-specific channel like `#wiremock-java` - [ ] Recommended: If you participate in Hacktoberfest 2023, make sure you're [signed up](https://wiremock.org/events/hacktoberfest/) there and in the WireMock form - [ ] The PR request is well described and justified, including the body and the references - [ ] The PR title represents the desired changelog entry - [ ] The repository's code style is followed (see the contributing guide) - [ ] Test coverage that demonstrates that the change works as expected - [ ] For new features, there's necessary documentation in this pull request or in a subsequent PR to [wiremock.org](https://github.com/wiremock/wiremock.org) <!-- Put an `x` into the [ ] to show you have filled the information. The template comes from https://github.com/wiremock/.github/blob/main/.github/pull_request_template.md You can override it by creating .github/pull_request_template.md in your own repository -->
- Loading branch information
Showing
6 changed files
with
140 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/main/java/org/wiremock/extensions/state/internal/ExtensionLogger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package org.wiremock.extensions.state.internal; | ||
|
||
import com.github.tomakehurst.wiremock.common.Notifier; | ||
|
||
import static com.github.tomakehurst.wiremock.common.LocalNotifier.notifier; | ||
|
||
public class ExtensionLogger { | ||
|
||
private static Notifier notifier; | ||
|
||
private ExtensionLogger() { | ||
notifier = notifier(); | ||
} | ||
|
||
public static ExtensionLogger logger() { | ||
return InstanceHolder.instance; | ||
} | ||
|
||
public void info(Context context, String message) { | ||
notifier.info(buildMessage(context.getContextName(), message)); | ||
} | ||
|
||
public void error(Context context, String message) { | ||
notifier.error(buildMessage(context.getContextName(), message)); | ||
} | ||
|
||
public void info(String contextName, String message) { | ||
notifier.info(buildMessage(contextName, message)); | ||
} | ||
|
||
public void error(String contextName, String message) { | ||
notifier.error(buildMessage(contextName, message)); | ||
} | ||
|
||
private String buildMessage(String contextName, String message) { | ||
return String.format("Context '%s': %s", contextName, message); | ||
} | ||
|
||
private static final class InstanceHolder { | ||
private static final ExtensionLogger instance = new ExtensionLogger(); | ||
} | ||
|
||
} |