use of com.dtflys.forest.logging.LogConfiguration in project forest by dromara.
the class AbstractHttpclientRequestSender method logRequest.
public <T extends HttpRequestBase> void logRequest(int retryCount, T httpReq) {
LogConfiguration logConfiguration = request.getLogConfiguration();
if (!logConfiguration.isLogEnabled() || !logConfiguration.isLogRequest()) {
return;
}
RequestLogMessage logMessage = getRequestLogMessage(retryCount, httpReq);
logMessage.setRequest(request);
request.setRequestLogMessage(logMessage);
ForestLogHandler logHandler = request.getLogConfiguration().getLogHandler();
if (logHandler != null) {
logHandler.logRequest(logMessage);
}
}
use of com.dtflys.forest.logging.LogConfiguration in project forest by dromara.
the class SyncHttpclientRequestSender method logResponse.
public void logResponse(ForestResponse response) {
LogConfiguration logConfiguration = request.getLogConfiguration();
if (!logConfiguration.isLogEnabled() || response.isLogged()) {
return;
}
response.setLogged(true);
ResponseLogMessage logMessage = new ResponseLogMessage(response, response.getStatusCode());
ForestLogHandler logHandler = logConfiguration.getLogHandler();
if (logHandler != null) {
if (logConfiguration.isLogResponseStatus()) {
logHandler.logResponseStatus(logMessage);
}
if (logConfiguration.isLogResponseContent()) {
logHandler.logResponseContent(logMessage);
}
}
}
use of com.dtflys.forest.logging.LogConfiguration in project forest by dromara.
the class OkHttp3Executor method logRequest.
public void logRequest(int retryCount, Request okRequest, OkHttpClient okHttpClient) {
LogConfiguration logConfiguration = request.getLogConfiguration();
if (!logConfiguration.isLogEnabled() || !logConfiguration.isLogRequest()) {
return;
}
RequestLogMessage logMessage = buildRequestMessage(retryCount, okRequest);
logMessage.setRequest(request);
logMessage.setRetryCount(retryCount);
Proxy proxy = okHttpClient.proxy();
if (proxy != null) {
RequestProxyLogMessage proxyLogMessage = new RequestProxyLogMessage();
SocketAddress address = proxy.address();
if (address instanceof InetSocketAddress) {
InetSocketAddress inetSocketAddress = (InetSocketAddress) address;
proxyLogMessage.setHost(inetSocketAddress.getHostString());
proxyLogMessage.setPort(inetSocketAddress.getPort() + "");
logMessage.setProxy(proxyLogMessage);
}
}
request.setRequestLogMessage(logMessage);
logConfiguration.getLogHandler().logRequest(logMessage);
}
use of com.dtflys.forest.logging.LogConfiguration in project forest by dromara.
the class BaseLogHandlerLifeCycle method onProxyHandlerInitialized.
@Override
public void onProxyHandlerInitialized(InterfaceProxyHandler interfaceProxyHandler, LogHandler annotation) {
ForestConfiguration configuration = interfaceProxyHandler.getConfiguration();
LogConfiguration logConfiguration = interfaceProxyHandler.getBaseLogConfiguration();
if (logConfiguration == null) {
logConfiguration = new LogConfiguration();
logConfiguration.setLogEnabled(configuration.isLogEnabled());
logConfiguration.setLogRequest(configuration.isLogRequest());
logConfiguration.setLogResponseStatus(configuration.isLogResponseStatus());
logConfiguration.setLogResponseContent(configuration.isLogResponseContent());
interfaceProxyHandler.setBaseLogConfiguration(logConfiguration);
}
Class<? extends ForestLogHandler> logHandlerClass = annotation.value();
ForestLogHandler logHandler = null;
try {
logHandler = logHandlerClass.newInstance();
} catch (InstantiationException e) {
throw new ForestRuntimeException(e);
} catch (IllegalAccessException e) {
throw new ForestRuntimeException(e);
}
if (logHandler != null) {
logConfiguration.setLogHandler(logHandler);
} else {
logConfiguration.setLogHandler(configuration.getLogHandler());
}
}
use of com.dtflys.forest.logging.LogConfiguration in project forest by dromara.
the class LogEnabledLifeCycle method onMethodInitialized.
@Override
public void onMethodInitialized(ForestMethod method, LogEnabled annotation) {
MetaRequest metaRequest = method.getMetaRequest();
if (metaRequest == null) {
return;
}
ForestConfiguration configuration = method.getConfiguration();
LogConfiguration logConfiguration = metaRequest.getLogConfiguration();
if (logConfiguration == null) {
logConfiguration = new LogConfiguration();
metaRequest.setLogConfiguration(logConfiguration);
}
boolean logEnabled = annotation.value();
boolean logRequest = annotation.logRequest();
boolean logResponseStatus = annotation.logResponseStatus();
boolean logResponseContent = annotation.logResponseContent();
logConfiguration.setLogEnabled(logEnabled);
logConfiguration.setLogRequest(logRequest);
logConfiguration.setLogResponseStatus(logResponseStatus);
logConfiguration.setLogResponseContent(logResponseContent);
metaRequest.setLogConfiguration(logConfiguration);
}
Aggregations