: 그럼 당신은 같이 server.xml에에 자신의 설정을 추가해야
public class LeKafkaAccesslogValve extends ValveBase implements AccessLog {
private String topic;
private String bootstrapServers;
// If set to zero then the producer will not wait for any acknowledgment from the server at all.
private String acks;
private String producerSize ;
private String properties;
private List<Producer<byte[], byte[]>> producerList;
private AtomicInteger producerIndex = new AtomicInteger(0);
private int timeoutMillis;
private boolean enabled = true;
private String pattern;
private AccessLogElement accessLogElement;
private String localeName;
private Locale locale = Locale.getDefault();
@Override
public void log(Request request, Response response, long l) {
if (producerList != null && getEnabled() && getState().isAvailable() && null != this.accessLogElement) {
try {
getNextProducer().send(new ProducerRecord<byte[], byte[]>(topic, this.accessLogElement.buildLog(request,response,time,this).getBytes(StandardCharsets.UTF_8))).get(timeoutMillis, TimeUnit.MILLISECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
log.error('accesslog in kafka exception', e);
}
}
}
@Override
public void setRequestAttributesEnabled(boolean b) {
//some other code if you would like
}
@Override
public boolean getRequestAttributesEnabled() {
//some other code if you would like
return false;
}
@Override
public void invoke(Request request, Response response) throws IOException, ServletException {
//some other code if you would like
}
}
:
그럼 당신은 클래스를 만들어야합니다, 시작하자 ValveBase 같은 AccessLog를 구현 확장합니다. 또한 로그 프레임 워크를 log4j2로 전환하면 효율성을 높일 수 있으므로 kafka에 메시지를 보내면 주된 속도가 저하되지 않습니다.
감사합니다. 장, 감사합니다. –