use of core.framework.impl.log.filter.BytesParam in project core-ng-project by neowu.
the class KafkaMessageListenerThread method handle.
private <T> void handle(String topic, KafkaMessageListener.MessageHandlerHolder<T> holder, List<ConsumerRecord<String, byte[]>> records, double longProcessThresholdInNano) {
for (ConsumerRecord<String, byte[]> record : records) {
ActionLog actionLog = logManager.begin("=== message handling begin ===");
try {
actionLog.action("topic:" + topic);
actionLog.context("topic", topic);
actionLog.context("handler", holder.handler.getClass().getCanonicalName());
actionLog.context("key", record.key());
logger.debug("message={}", new BytesParam(record.value()));
T message = holder.reader.fromJSON(record.value());
Headers headers = record.headers();
actionLog.refId(header(headers, KafkaHeaders.HEADER_REF_ID));
String client = header(headers, KafkaHeaders.HEADER_CLIENT);
if (client != null)
actionLog.context("client", client);
String clientIP = header(headers, KafkaHeaders.HEADER_CLIENT_IP);
if (clientIP != null)
actionLog.context("clientIP", clientIP);
if ("true".equals(header(headers, KafkaHeaders.HEADER_TRACE))) {
actionLog.trace = true;
}
holder.validator.validate(message);
holder.handler.handle(record.key(), message);
} catch (Throwable e) {
logManager.logError(e);
} finally {
long elapsedTime = actionLog.elapsedTime();
if (elapsedTime > longProcessThresholdInNano) {
logger.warn(Markers.errorCode("LONG_PROCESS"), "took too long to process message, elapsedTime={}", elapsedTime);
}
logManager.end("=== message handling end ===");
}
}
}
use of core.framework.impl.log.filter.BytesParam in project core-ng-project by neowu.
the class TextBody method send.
@Override
public void send(Sender sender, ResponseHandlerContext context) {
byte[] bytes = Strings.bytes(text);
logger.debug("[response] body={}", new BytesParam(bytes));
sender.send(ByteBuffer.wrap(bytes));
}
use of core.framework.impl.log.filter.BytesParam in project core-ng-project by neowu.
the class RequestParser method logRequestBody.
private void logRequestBody(RequestImpl request) {
ContentType contentType = request.contentType;
if (contentType == null)
return;
Object bodyParam = null;
if (ContentType.APPLICATION_JSON.mediaType().equals(contentType.mediaType())) {
bodyParam = new JSONParam(request.body, contentType.charset().orElse(Charsets.UTF_8));
} else if (ContentType.TEXT_XML.mediaType().equals(contentType.mediaType())) {
bodyParam = new BytesParam(request.body, contentType.charset().orElse(Charsets.UTF_8));
}
if (bodyParam != null)
logger.debug("[request] body={}", bodyParam);
}
use of core.framework.impl.log.filter.BytesParam in project core-ng-project by neowu.
the class HTTPClientImpl method logRequestBody.
private void logRequestBody(HTTPRequest request, ContentType contentType) {
Object bodyParam;
if (ContentType.APPLICATION_JSON.mediaType().equals(contentType.mediaType())) {
bodyParam = new JSONParam(request.body(), contentType.charset().orElse(Charsets.UTF_8));
} else {
bodyParam = new BytesParam(request.body());
}
logger.debug("[request] contentType={}, body={}", contentType, bodyParam);
}
use of core.framework.impl.log.filter.BytesParam in project core-ng-project by neowu.
the class RedisImpl method set.
public void set(String key, byte[] value, Duration expiration) {
StopWatch watch = new StopWatch();
PoolItem<RedisConnection> item = pool.borrowItem();
try {
RedisConnection connection = item.resource;
connection.write(Protocol.Command.SETEX, encode(key), encode(expiration.getSeconds()), value);
connection.readSimpleString();
} catch (IOException e) {
item.broken = true;
throw new UncheckedIOException(e);
} finally {
pool.returnItem(item);
long elapsedTime = watch.elapsedTime();
ActionLogContext.track("redis", elapsedTime, 0, 1);
logger.debug("set, key={}, value={}, expiration={}, elapsedTime={}", key, new BytesParam(value), expiration, elapsedTime);
checkSlowOperation(elapsedTime);
}
}
Aggregations