ee.bitweb.core.logging.SilencedGelfTcpAppender Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spring-core Show documentation
Show all versions of spring-core Show documentation
Bitweb Spring Boot Java Core Library
The newest version!
package ee.bitweb.core.logging;
import ch.qos.logback.classic.spi.ILoggingEvent;
import de.siegmar.logbackgelf.GelfTcpAppender;
import ee.bitweb.core.exception.CoreException;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class SilencedGelfTcpAppender extends GelfTcpAppender {
@Override
protected void append(final ILoggingEvent event) {
final byte[] binMessage = getEncoder().encode(event);
try {
appendMessage(binMessage);
} catch (CoreException ignored) {
// Catching and ignoring CoreException which will be thrown if application can't connect to Graylog, because we don't want the application
// to stop.
}
}
@Override
protected void appendMessage(final byte[] messageToSend) {
try {
super.appendMessage(messageToSend);
} catch (CoreException e) {
throw new CoreException("Error sending GELF message", e);
}
}
@Override
public void addError(String msg, Throwable ex) {
throw new CoreException(msg, ex);
}
}