Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1173,15 +1173,32 @@ public Duration getReconnectionDelay() {
* @see PreferPrimaryDestinationConnectionStrategy#setSecondaryConnectionTTL(Duration)
* @param secondaryConnectionTTL the TTL of a connection when connected to a secondary destination
* @throws IllegalStateException if the {@link #connectionStrategy} is not a {@link PreferPrimaryDestinationConnectionStrategy}
*
* @deprecated use {@link PreferPrimaryDestinationConnectionStrategy#setSecondaryConnectionTTL(Duration)} instead.
*/
@Deprecated
public void setSecondaryConnectionTTL(Duration secondaryConnectionTTL) {
addWarn(
"Setting <secondaryConnectionTTL> directly on the appender is deprecated. "
+ "Instead you should explicitly set the connection strategy to <preferPrimary> and set its <secondaryConnectionTTL> property to the desired value.");

if (connectionStrategy instanceof PreferPrimaryDestinationConnectionStrategy) {
((PreferPrimaryDestinationConnectionStrategy) connectionStrategy).setSecondaryConnectionTTL(secondaryConnectionTTL);
} else {
throw new IllegalStateException(String.format("When setting the secondaryConnectionTTL, the strategy must be a %s. It is currently a %s", PreferPrimaryDestinationConnectionStrategy.class, connectionStrategy));
}
}

/**
* Convenience method for accessing {@link PreferPrimaryDestinationConnectionStrategy#getSecondaryConnectionTTL()}.
*
* @return the secondary connection TTL or {@code null} if the connection strategy is not a {@link PreferPrimaryDestinationConnectionStrategy}.
* @deprecated use {@link PreferPrimaryDestinationConnectionStrategy#getSecondaryConnectionTTL()} instead.
*
* @see #getConnectionStrategy()
* @see PreferPrimaryDestinationConnectionStrategy#getSecondaryConnectionTTL()
*/
@Deprecated
public Duration getSecondaryConnectionTTL() {
if (connectionStrategy instanceof PreferPrimaryDestinationConnectionStrategy) {
return ((PreferPrimaryDestinationConnectionStrategy) connectionStrategy).getSecondaryConnectionTTL();
Expand Down Expand Up @@ -1237,7 +1254,7 @@ public void setWriteBufferSize(int writeBufferSize) {
* Alias for {@link #getRingBufferSize()}.
*
* @return the size of the ring buffer
* @deprecated use {@link #getRingBufferSize()} instead
* @deprecated use {@link #getRingBufferSize()} instead.
*/
@Deprecated
public int getQueueSize() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.BasicStatusManager;
import ch.qos.logback.core.encoder.Encoder;
import ch.qos.logback.core.status.OnConsoleStatusListener;
import ch.qos.logback.core.status.Status;
import ch.qos.logback.core.status.StatusManager;
import ch.qos.logback.core.util.Duration;
Expand All @@ -84,8 +85,6 @@ public class LogstashTcpSocketAppenderTest {
@InjectMocks
private final LogstashTcpSocketAppender appender = new TestableLogstashTcpSocketAppender();

private LoggerContext context = new LoggerContext();

private StatusManager statusManager = new BasicStatusManager();

@Mock
Expand Down Expand Up @@ -121,6 +120,13 @@ protected Future<?> scheduleReaderCallable(Callable<Void> readerCallable) {

@BeforeEach
public void setup() throws IOException {
// Output statuses on the console for easy debugging. Must be initialized early to capture
// warnings emitted by setter/getter methods before the appender is started.
OnConsoleStatusListener consoleListener = new OnConsoleStatusListener();
consoleListener.start();
statusManager.add(consoleListener);

LoggerContext context = new LoggerContext();
context.setStatusManager(statusManager);

when(socketFactory.createSocket()).thenReturn(socket);
Expand Down