-
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
- 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(); | ||
} | ||
|
||
} |