-
Notifications
You must be signed in to change notification settings - Fork 291
feat: add prefix monitor #3621
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
Merged
jimmarino
merged 14 commits into
eclipse-edc:main
from
mercedes-benz:feat/add-prefix-monitor
Nov 22, 2023
Merged
feat: add prefix monitor #3621
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
b27df54
feat: add PrefixMonitor (#3510)
hamidonos b1567fc
Merge remote-tracking branch 'upstream/main'
hamidonos d8a378a
Merge remote-tracking branch 'origin/main'
hamidonos e38cd16
fix: fix checkstyle error for PrefixMonitor
hamidonos f951bca
fix: pr comment updates
hamidonos 823b374
fix: pr comment updates
hamidonos f943fe1
fix: pr comment updates
hamidonos 0a53890
fix: checkstyle error
hamidonos d6dd96b
fix: remove mockito reset before each test in PrefixMonitorTest
hamidonos f6faf1e
fix: checkstyle test
hamidonos 62e0604
fix: rollback changes in TransferRequest
hamidonos d35b7bc
Merge remote-tracking branch 'upstream/main' into feat/add-prefix-mon…
hamidonos 496e306
fix: add javadoc to Monitor withPrefix method
hamidonos bf36d5c
fix: change javadoc highlighting
hamidonos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
74 changes: 74 additions & 0 deletions
74
spi/common/core-spi/src/main/java/org/eclipse/edc/spi/monitor/PrefixMonitor.java
This file contains hidden or 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,74 @@ | ||
| /* | ||
| * Copyright (c) 2023 Mercedes-Benz Tech Innovation GmbH | ||
| * | ||
| * This program and the accompanying materials are made available under the | ||
| * terms of the Apache License, Version 2.0 which is available at | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * Contributors: | ||
| * Mercedes-Benz Tech Innovation GmbH - initial implementation | ||
| * | ||
| */ | ||
|
|
||
| package org.eclipse.edc.spi.monitor; | ||
|
|
||
| import java.util.function.Supplier; | ||
|
|
||
| /** | ||
| * Monitor implementation which will prefix a supplied text to all log messages. | ||
| * Note that this monitor will delegate the actual log execution to the underlying monitor provided by the context. | ||
| */ | ||
| class PrefixMonitor implements Monitor { | ||
|
|
||
| private static final String MESSAGE_FORMAT = "[%s] %s"; | ||
|
|
||
| private final Monitor monitor; | ||
| private final String prefix; | ||
|
|
||
| PrefixMonitor(Monitor monitor, String prefix) { | ||
| this.monitor = monitor; | ||
| this.prefix = prefix; | ||
| } | ||
|
|
||
| @Override | ||
| public void severe(Supplier<String> supplier, Throwable... errors) { | ||
| monitor.severe(() -> MESSAGE_FORMAT.formatted(prefix, supplier.get()), errors); | ||
| } | ||
|
|
||
| @Override | ||
| public void severe(String message, Throwable... errors) { | ||
| monitor.severe(MESSAGE_FORMAT.formatted(prefix, message), errors); | ||
| } | ||
|
|
||
| @Override | ||
| public void warning(Supplier<String> supplier, Throwable... errors) { | ||
| monitor.warning(() -> MESSAGE_FORMAT.formatted(prefix, supplier.get()), errors); | ||
| } | ||
|
|
||
| @Override | ||
| public void warning(String message, Throwable... errors) { | ||
| monitor.warning(MESSAGE_FORMAT.formatted(prefix, message), errors); | ||
| } | ||
|
|
||
| @Override | ||
| public void info(Supplier<String> supplier, Throwable... errors) { | ||
| monitor.info(() -> MESSAGE_FORMAT.formatted(prefix, supplier.get()), errors); | ||
| } | ||
|
|
||
| @Override | ||
| public void info(String message, Throwable... errors) { | ||
| monitor.info(MESSAGE_FORMAT.formatted(prefix, message), errors); | ||
| } | ||
|
|
||
| @Override | ||
| public void debug(Supplier<String> supplier, Throwable... errors) { | ||
| monitor.debug(() -> MESSAGE_FORMAT.formatted(prefix, supplier.get()), errors); | ||
| } | ||
|
|
||
| @Override | ||
| public void debug(String message, Throwable... errors) { | ||
| monitor.debug(MESSAGE_FORMAT.formatted(prefix, message), errors); | ||
| } | ||
| } |
81 changes: 81 additions & 0 deletions
81
spi/common/core-spi/src/test/java/org/eclipse/edc/spi/monitor/PrefixMonitorTest.java
This file contains hidden or 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,81 @@ | ||
| /* | ||
| * Copyright (c) 2023 Mercedes-Benz Tech Innovation GmbH | ||
| * | ||
| * This program and the accompanying materials are made available under the | ||
| * terms of the Apache License, Version 2.0 which is available at | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * Contributors: | ||
| * Mercedes-Benz Tech Innovation GmbH - initial implementation | ||
| * | ||
| */ | ||
|
|
||
| package org.eclipse.edc.spi.monitor; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
| import org.mockito.Mockito; | ||
|
|
||
| import java.util.function.Supplier; | ||
|
|
||
| import static org.mockito.ArgumentMatchers.argThat; | ||
| import static org.mockito.ArgumentMatchers.eq; | ||
| import static org.mockito.Mockito.verify; | ||
|
|
||
| class PrefixMonitorTest { | ||
|
|
||
| private static final String TEST_PREFIX = "Test Prefix"; | ||
| private static final String TEST_MESSAGE = "Test Message"; | ||
| private static final String EXPECTED_MESSAGE = "[Test Prefix] Test Message"; | ||
| private final Monitor mockMonitor = Mockito.mock(); | ||
| private final Monitor prefixMonitor = new PrefixMonitor(mockMonitor, TEST_PREFIX); | ||
|
|
||
| @Test | ||
| void logSevere_byMessageSupplier_logIsDelegated() { | ||
| prefixMonitor.severe(() -> TEST_MESSAGE); | ||
| verify(mockMonitor).severe(argThat((Supplier<String> supplier) -> EXPECTED_MESSAGE.equals(supplier.get()))); | ||
| } | ||
|
|
||
| @Test | ||
| void logSevere_byMessageString_logIsDelegated() { | ||
| prefixMonitor.severe(TEST_MESSAGE); | ||
| verify(mockMonitor).severe(eq(EXPECTED_MESSAGE)); | ||
| } | ||
|
|
||
| @Test | ||
| void logWarning_byMessageSupplier_logIsDelegated() { | ||
| prefixMonitor.warning(() -> TEST_MESSAGE); | ||
| verify(mockMonitor).warning(argThat((Supplier<String> supplier) -> EXPECTED_MESSAGE.equals(supplier.get()))); | ||
| } | ||
|
|
||
| @Test | ||
| void logWarning_byMessageString_logIsDelegated() { | ||
| prefixMonitor.warning(TEST_MESSAGE); | ||
| verify(mockMonitor).warning(eq(EXPECTED_MESSAGE)); | ||
| } | ||
|
|
||
| @Test | ||
| void logInfo_byMessageSupplier_logIsDelegated() { | ||
| prefixMonitor.info(() -> TEST_MESSAGE); | ||
| verify(mockMonitor).info(argThat((Supplier<String> supplier) -> EXPECTED_MESSAGE.equals(supplier.get()))); | ||
| } | ||
|
|
||
| @Test | ||
| void logInfo_byMessageString_logIsDelegated() { | ||
| prefixMonitor.info(TEST_MESSAGE); | ||
| verify(mockMonitor).info(eq(EXPECTED_MESSAGE)); | ||
| } | ||
|
|
||
| @Test | ||
| void logDebug_byMessageSupplier_logIsDelegated() { | ||
| prefixMonitor.debug(() -> TEST_MESSAGE); | ||
| verify(mockMonitor).debug(argThat((Supplier<String> supplier) -> EXPECTED_MESSAGE.equals(supplier.get()))); | ||
| } | ||
|
|
||
| @Test | ||
| void logDebug_byMessageString_logIsDelegated() { | ||
| prefixMonitor.debug(TEST_MESSAGE); | ||
| verify(mockMonitor).debug(eq(EXPECTED_MESSAGE)); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.