use of org.apache.dubbo.rpc.support.AccessLogData in project dubbo by alibaba.
the class AccessLogFilterTest method testDefault.
// TODO how to assert thread action
@Test
@SuppressWarnings("unchecked")
public void testDefault() throws NoSuchFieldException, IllegalAccessException {
URL url = URL.valueOf("test://test:11/test?accesslog=true&group=dubbo&version=1.1");
Invoker<AccessLogFilterTest> invoker = new MyInvoker<AccessLogFilterTest>(url);
Invocation invocation = new MockInvocation();
Field field = AccessLogFilter.class.getDeclaredField("LOG_ENTRIES");
ReflectUtils.makeAccessible(field);
assertTrue(((Map) field.get(AccessLogFilter.class)).isEmpty());
accessLogFilter.invoke(invoker, invocation);
Map<String, Queue<AccessLogData>> logs = (Map<String, Queue<AccessLogData>>) field.get(AccessLogFilter.class);
assertFalse(logs.isEmpty());
assertFalse(logs.get("true").isEmpty());
AccessLogData log = logs.get("true").iterator().next();
assertEquals("org.apache.dubbo.rpc.support.DemoService", log.getServiceName());
}
use of org.apache.dubbo.rpc.support.AccessLogData in project dubbo by alibaba.
the class AccessLogFilter method invoke.
/**
* This method logs the access log for service method invocation call.
*
* @param invoker service
* @param inv Invocation service method.
* @return Result from service method.
* @throws RpcException
*/
@Override
public Result invoke(Invoker<?> invoker, Invocation inv) throws RpcException {
try {
String accessLogKey = invoker.getUrl().getParameter(ACCESS_LOG_KEY);
if (ConfigUtils.isNotEmpty(accessLogKey)) {
AccessLogData logData = AccessLogData.newLogData();
logData.buildAccessLogData(invoker, inv);
log(accessLogKey, logData);
}
} catch (Throwable t) {
logger.warn("Exception in AccessLogFilter of service(" + invoker + " -> " + inv + ")", t);
}
return invoker.invoke(inv);
}
use of org.apache.dubbo.rpc.support.AccessLogData in project dubbo by alibaba.
the class AccessLogFilter method processWithServiceLogger.
private void processWithServiceLogger(Queue<AccessLogData> logQueue) {
for (Iterator<AccessLogData> iterator = logQueue.iterator(); iterator.hasNext(); iterator.remove()) {
AccessLogData logData = iterator.next();
LoggerFactory.getLogger(LOG_KEY + "." + logData.getServiceName()).info(logData.getLogMessage());
}
}
use of org.apache.dubbo.rpc.support.AccessLogData in project dubbo by alibaba.
the class AccessLogFilter method processWithAccessKeyLogger.
private void processWithAccessKeyLogger(Queue<AccessLogData> logQueue, File file) throws IOException {
try (FileWriter writer = new FileWriter(file, true)) {
for (Iterator<AccessLogData> iterator = logQueue.iterator(); iterator.hasNext(); iterator.remove()) {
writer.write(iterator.next().getLogMessage());
writer.write(System.getProperty(LINE_SEPARATOR));
}
writer.flush();
}
}
Aggregations