Search in sources :

Example 81 with Log

use of org.apache.commons.logging.Log in project alluxio by Alluxio.

the class LogUtils method setLogLevel.

/**
 * Gets a logger's level with specify name, if the level argument is not null, it will set to
 * specify level first.
 * @param logName logger's name
 * @param level logger's level
 * @return an entity object about the log info
 * @throws IOException if an I/O error occurs
 */
public static LogInfo setLogLevel(String logName, String level) throws IOException {
    LogInfo result = new LogInfo();
    if (StringUtils.isNotBlank(logName)) {
        result.setLogName(logName);
        Log log = LogFactory.getLog(logName);
        Logger logger = LoggerFactory.getLogger(logName);
        if (log instanceof Log4JLogger) {
            process(((Log4JLogger) log).getLogger(), level, result);
        } else if (log instanceof Jdk14Logger) {
            process(((Jdk14Logger) log).getLogger(), level, result);
        } else if (logger instanceof Log4jLoggerAdapter) {
            try {
                Field field = Log4jLoggerAdapter.class.getDeclaredField("logger");
                field.setAccessible(true);
                org.apache.log4j.Logger log4jLogger = (org.apache.log4j.Logger) field.get(logger);
                process(log4jLogger, level, result);
            } catch (NoSuchFieldException | IllegalAccessException e) {
                result.setMessage(e.getMessage());
            }
        } else {
            result.setMessage("Sorry, " + log.getClass() + " not supported.");
        }
    } else {
        result.setMessage("Please specify a correct logName.");
    }
    return result;
}
Also used : LogInfo(alluxio.wire.LogInfo) Jdk14Logger(org.apache.commons.logging.impl.Jdk14Logger) Log(org.apache.commons.logging.Log) Log4JLogger(org.apache.commons.logging.impl.Log4JLogger) Logger(org.slf4j.Logger) Log4JLogger(org.apache.commons.logging.impl.Log4JLogger) Jdk14Logger(org.apache.commons.logging.impl.Jdk14Logger) Log4jLoggerAdapter(org.slf4j.impl.Log4jLoggerAdapter) Field(java.lang.reflect.Field)

Example 82 with Log

use of org.apache.commons.logging.Log in project spring-framework by spring-projects.

the class HttpHandlerConnector method doConnect.

private Mono<ClientHttpResponse> doConnect(HttpMethod httpMethod, URI uri, Function<? super ClientHttpRequest, Mono<Void>> requestCallback) {
    // unsafe(): we're intercepting, already serialized Publisher signals
    Sinks.Empty<Void> requestWriteSink = Sinks.unsafe().empty();
    Sinks.Empty<Void> handlerSink = Sinks.unsafe().empty();
    ClientHttpResponse[] savedResponse = new ClientHttpResponse[1];
    MockClientHttpRequest mockClientRequest = new MockClientHttpRequest(httpMethod, uri);
    MockServerHttpResponse mockServerResponse = new MockServerHttpResponse();
    mockClientRequest.setWriteHandler(requestBody -> {
        log("Invoking HttpHandler for ", httpMethod, uri);
        ServerHttpRequest mockServerRequest = adaptRequest(mockClientRequest, requestBody);
        ServerHttpResponse responseToUse = prepareResponse(mockServerResponse, mockServerRequest);
        this.handler.handle(mockServerRequest, responseToUse).subscribe(aVoid -> {
        }, // Ignore result: signals cannot compete
        handlerSink::tryEmitError, handlerSink::tryEmitEmpty);
        return Mono.empty();
    });
    mockServerResponse.setWriteHandler(responseBody -> Mono.fromRunnable(() -> {
        log("Creating client response for ", httpMethod, uri);
        savedResponse[0] = adaptResponse(mockServerResponse, responseBody);
    }));
    log("Writing client request for ", httpMethod, uri);
    requestCallback.apply(mockClientRequest).subscribe(aVoid -> {
    }, // Ignore result: signals cannot compete
    requestWriteSink::tryEmitError, requestWriteSink::tryEmitEmpty);
    return Mono.when(requestWriteSink.asMono(), handlerSink.asMono()).onErrorMap(ex -> {
        ClientHttpResponse response = savedResponse[0];
        return response != null ? new FailureAfterResponseCompletedException(response, ex) : ex;
    }).then(Mono.fromCallable(() -> savedResponse[0] != null ? savedResponse[0] : adaptResponse(mockServerResponse, Flux.empty())));
}
Also used : Sinks(reactor.core.publisher.Sinks) ServerHttpResponse(org.springframework.http.server.reactive.ServerHttpResponse) Function(java.util.function.Function) ClientHttpResponse(org.springframework.http.client.reactive.ClientHttpResponse) HttpCookie(org.springframework.http.HttpCookie) Schedulers(reactor.core.scheduler.Schedulers) ClientHttpRequest(org.springframework.http.client.reactive.ClientHttpRequest) URI(java.net.URI) ServerHttpRequest(org.springframework.http.server.reactive.ServerHttpRequest) MockClientHttpResponse(org.springframework.mock.http.client.reactive.MockClientHttpResponse) MockServerHttpRequest(org.springframework.mock.http.server.reactive.MockServerHttpRequest) HttpHeaders(org.springframework.http.HttpHeaders) Publisher(org.reactivestreams.Publisher) HttpMethod(org.springframework.http.HttpMethod) MultiValueMap(org.springframework.util.MultiValueMap) Mono(reactor.core.publisher.Mono) HttpHeadResponseDecorator(org.springframework.http.server.reactive.HttpHeadResponseDecorator) DataBuffer(org.springframework.core.io.buffer.DataBuffer) Flux(reactor.core.publisher.Flux) HttpHandler(org.springframework.http.server.reactive.HttpHandler) Log(org.apache.commons.logging.Log) LogFactory(org.apache.commons.logging.LogFactory) MockServerHttpResponse(org.springframework.mock.http.server.reactive.MockServerHttpResponse) ClientHttpConnector(org.springframework.http.client.reactive.ClientHttpConnector) MockClientHttpRequest(org.springframework.mock.http.client.reactive.MockClientHttpRequest) Assert(org.springframework.util.Assert) Sinks(reactor.core.publisher.Sinks) ServerHttpRequest(org.springframework.http.server.reactive.ServerHttpRequest) MockServerHttpRequest(org.springframework.mock.http.server.reactive.MockServerHttpRequest) MockClientHttpRequest(org.springframework.mock.http.client.reactive.MockClientHttpRequest) MockServerHttpResponse(org.springframework.mock.http.server.reactive.MockServerHttpResponse) ServerHttpResponse(org.springframework.http.server.reactive.ServerHttpResponse) MockServerHttpResponse(org.springframework.mock.http.server.reactive.MockServerHttpResponse) ClientHttpResponse(org.springframework.http.client.reactive.ClientHttpResponse) MockClientHttpResponse(org.springframework.mock.http.client.reactive.MockClientHttpResponse)

Example 83 with Log

use of org.apache.commons.logging.Log in project netty by netty.

the class CommonsLoggerTest method testWarn.

@Test
public void testWarn() {
    Log mockLog = mock(Log.class);
    InternalLogger logger = new CommonsLogger(mockLog, "foo");
    logger.warn("a");
    verify(mockLog).warn("a");
}
Also used : Log(org.apache.commons.logging.Log) Test(org.junit.jupiter.api.Test)

Example 84 with Log

use of org.apache.commons.logging.Log in project netty by netty.

the class CommonsLoggerTest method testIsInfoEnabled.

@Test
public void testIsInfoEnabled() {
    Log mockLog = mock(Log.class);
    when(mockLog.isInfoEnabled()).thenReturn(true);
    InternalLogger logger = new CommonsLogger(mockLog, "foo");
    assertTrue(logger.isInfoEnabled());
    verify(mockLog).isInfoEnabled();
}
Also used : Log(org.apache.commons.logging.Log) Test(org.junit.jupiter.api.Test)

Example 85 with Log

use of org.apache.commons.logging.Log in project netty by netty.

the class CommonsLoggerTest method testWarnWithException.

@Test
public void testWarnWithException() {
    Log mockLog = mock(Log.class);
    InternalLogger logger = new CommonsLogger(mockLog, "foo");
    logger.warn("a", e);
    verify(mockLog).warn("a", e);
}
Also used : Log(org.apache.commons.logging.Log) Test(org.junit.jupiter.api.Test)

Aggregations

Log (org.apache.commons.logging.Log)188 Test (org.junit.Test)51 Test (org.junit.jupiter.api.Test)40 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)35 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)19 BeanFactory (org.springframework.beans.factory.BeanFactory)17 CountDownLatch (java.util.concurrent.CountDownLatch)15 LogConfigurationException (org.apache.commons.logging.LogConfigurationException)15 ArrayList (java.util.ArrayList)12 File (java.io.File)11 QueueChannel (org.springframework.integration.channel.QueueChannel)11 MethodInvocation (org.aopalliance.intercept.MethodInvocation)10 IOException (java.io.IOException)9 AtomicReference (java.util.concurrent.atomic.AtomicReference)9 Log4JLogger (org.apache.commons.logging.impl.Log4JLogger)9 Message (org.springframework.messaging.Message)8 List (java.util.List)7 ApplicationEventPublisher (org.springframework.context.ApplicationEventPublisher)7 InputStream (java.io.InputStream)6 LogFactory (org.apache.commons.logging.LogFactory)6