Skip to content

Commit

Permalink
Fix indexer logging
Browse files Browse the repository at this point in the history
  • Loading branch information
theotherp committed Oct 21, 2024
1 parent 958dbcd commit 98e82e0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
15 changes: 7 additions & 8 deletions core/src/main/java/org/nzbhydra/indexers/Indexer.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
import java.util.regex.Pattern;
import java.util.stream.Collectors;

@SuppressWarnings("TypeParameterHidesVisibleType")
@SuppressWarnings({"TypeParameterHidesVisibleType", "StringConcatenationArgumentToLogCall"})
@Reflective
@Component
public abstract class Indexer<T> {
Expand Down Expand Up @@ -479,7 +479,6 @@ public Optional<Instant> tryParseDate(String dateString) {
}



@Override
public boolean equals(Object o) {
if (this == o) {
Expand All @@ -503,27 +502,27 @@ public String toString() {
}

protected void warn(String msg) {
getLogger().warn("{}: {}", getName(), msg);
getLogger().warn(getName() + ": " + msg);
}

protected void error(String msg) {
getLogger().error("{}: {}", getName(), msg);
getLogger().error(getName() + ": " + msg);
}

protected void error(String msg, Throwable t) {
getLogger().error("{}: {}", getName(), msg, t);
getLogger().error(getName() + ": " + msg, t);
}

protected void info(String msg, Object... arguments) {
getLogger().info("{}: {}", getName(), msg, arguments);
getLogger().info(getName() + ": " + msg, arguments);
}

protected void debug(String msg, Object... arguments) {
getLogger().debug("{}: {}", getName(), msg, arguments);
getLogger().debug(getName() + ": " + msg, arguments);
}

protected void debug(Marker marker, String msg, Object... arguments) {
getLogger().debug(marker, "{}: {}", getName(), msg, arguments);
getLogger().debug(marker, getName() + ": " + msg, arguments);
}

protected abstract Logger getLogger();
Expand Down
9 changes: 7 additions & 2 deletions core/src/test/java/org/nzbhydra/indexers/IndexerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@

public class IndexerTest {

private Logger testLogger = LoggerFactory.getLogger("test");
private BaseConfig baseConfig;
private IndexerEntity indexerEntityMock = new IndexerEntity("indexerName");
private IndexerConfig indexerConfig = new IndexerConfig();
Expand Down Expand Up @@ -109,7 +110,7 @@ private Indexer<String> getTestee() {
return new Indexer<>() {
@Override
protected Logger getLogger() {
return LoggerFactory.getLogger("test");
return testLogger;
}


Expand Down Expand Up @@ -152,6 +153,7 @@ public void setUp() throws Exception {

testee.indexer = indexerEntityMock;
testee.config = indexerConfig;
indexerConfig.setName("testIndexer");
indexerConfig.setTimeout(1);
baseConfig = new BaseConfig();
when(configProviderMock.getBaseConfig()).thenReturn(baseConfig);
Expand Down Expand Up @@ -364,8 +366,11 @@ void shouldRemoveTrailing2() {
testee.cleanUpTitle("abc trailing1 trailing2");
}
System.out.println(stopwatch.elapsed(TimeUnit.MILLISECONDS));
}


@Test
public void shouldLogWithMessages() {
testee.info("Some message {}", "arg1");
}


Expand Down

0 comments on commit 98e82e0

Please sign in to comment.