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;
}
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())));
}
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");
}
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();
}
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);
}
Aggregations