Search in sources :

Example 1 with LogConfiguration

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);
    }
}
Also used : RequestLogMessage(com.dtflys.forest.logging.RequestLogMessage) ForestLogHandler(com.dtflys.forest.logging.ForestLogHandler) LogConfiguration(com.dtflys.forest.logging.LogConfiguration)

Example 2 with LogConfiguration

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);
        }
    }
}
Also used : ForestLogHandler(com.dtflys.forest.logging.ForestLogHandler) LogConfiguration(com.dtflys.forest.logging.LogConfiguration) ResponseLogMessage(com.dtflys.forest.logging.ResponseLogMessage)

Example 3 with LogConfiguration

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);
}
Also used : RequestLogMessage(com.dtflys.forest.logging.RequestLogMessage) Proxy(java.net.Proxy) InetSocketAddress(java.net.InetSocketAddress) RequestProxyLogMessage(com.dtflys.forest.logging.RequestProxyLogMessage) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) LogConfiguration(com.dtflys.forest.logging.LogConfiguration)

Example 4 with LogConfiguration

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());
    }
}
Also used : ForestConfiguration(com.dtflys.forest.config.ForestConfiguration) ForestLogHandler(com.dtflys.forest.logging.ForestLogHandler) ForestRuntimeException(com.dtflys.forest.exceptions.ForestRuntimeException) LogConfiguration(com.dtflys.forest.logging.LogConfiguration)

Example 5 with LogConfiguration

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);
}
Also used : ForestConfiguration(com.dtflys.forest.config.ForestConfiguration) MetaRequest(com.dtflys.forest.reflection.MetaRequest) LogConfiguration(com.dtflys.forest.logging.LogConfiguration)

Aggregations

LogConfiguration (com.dtflys.forest.logging.LogConfiguration)11 ForestLogHandler (com.dtflys.forest.logging.ForestLogHandler)6 ForestConfiguration (com.dtflys.forest.config.ForestConfiguration)3 ForestRuntimeException (com.dtflys.forest.exceptions.ForestRuntimeException)3 ForestConverter (com.dtflys.forest.converter.ForestConverter)2 RequestLogMessage (com.dtflys.forest.logging.RequestLogMessage)2 ResponseLogMessage (com.dtflys.forest.logging.ResponseLogMessage)2 MetaRequest (com.dtflys.forest.reflection.MetaRequest)2 ForestDataType (com.dtflys.forest.utils.ForestDataType)2 ContentType (com.dtflys.forest.backend.ContentType)1 ForestEncoder (com.dtflys.forest.converter.ForestEncoder)1 DownloadFile (com.dtflys.forest.extensions.DownloadFile)1 ForestQueryParameter (com.dtflys.forest.http.ForestQueryParameter)1 ForestRequest (com.dtflys.forest.http.ForestRequest)1 ForestRequestType (com.dtflys.forest.http.ForestRequestType)1 ForestResponse (com.dtflys.forest.http.ForestResponse)1 DefaultLogHandler (com.dtflys.forest.logging.DefaultLogHandler)1 RequestProxyLogMessage (com.dtflys.forest.logging.RequestProxyLogMessage)1 MappingParameter (com.dtflys.forest.mapping.MappingParameter)1 MappingTemplate (com.dtflys.forest.mapping.MappingTemplate)1