|
@@ -1,7 +1,6 @@
|
|
|
package com.elab.mongodb.chain;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
-import com.dianping.cat.Cat;
|
|
|
import com.elab.core.componts.chains.ComponentConsumerHandlerChain;
|
|
|
import com.elab.core.componts.chains.ComponentSupplierHandlerChain;
|
|
|
import com.elab.log.utils.CatCrossProcess;
|
|
@@ -9,6 +8,7 @@ import com.elab.mongodb.chain.model.MongoExecutorRequest;
|
|
|
import com.elab.mongodb.chain.model.MongoInsertRequest;
|
|
|
import com.elab.mongodb.chain.model.MongoQueryRequest;
|
|
|
import com.elab.mongodb.chain.model.MongoUpdateRequest;
|
|
|
+import com.elab.mongodb.utils.LogUtils;
|
|
|
import com.mongodb.DBObject;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -55,7 +55,6 @@ public class CatMongoInterceptInvoke implements MongoInterceptInvoke {
|
|
|
String type = String.format("%s - %s", collectionName, MongoActionOperation.INSERT.name());
|
|
|
CatCrossProcess.processTransactionMsg("mongodb", type, (t) -> {
|
|
|
logger.info("请求入参: " + JSON.toJSONString(objectToSave));
|
|
|
- logger.info("---------->>>>>>>>>>>>>>>" + Cat.getCurrentMessageId());
|
|
|
chain.run(request, MongoInterceptInvoke::insert);
|
|
|
return null;
|
|
|
});
|
|
@@ -74,11 +73,10 @@ public class CatMongoInterceptInvoke implements MongoInterceptInvoke {
|
|
|
try {
|
|
|
String type = String.format("%s - %s", collectionName, MongoActionOperation.UPDATE.name());
|
|
|
return CatCrossProcess.processTransactionMsg("mongodb", type, (t) -> {
|
|
|
- logger.info("---------->>>>>>>>>>>>>>>" + Cat.getCurrentMessageId());
|
|
|
logger.debug(" query : {}", getString(query));
|
|
|
logger.debug(" update : {} ", getString(update));
|
|
|
T executor = chain.executor(request, MongoInterceptInvoke::update);
|
|
|
- logger.info("mongo result : {}", getJsonString(executor));
|
|
|
+ logger.info("mongo result : {}", LogUtils.getJsonString(executor));
|
|
|
return executor;
|
|
|
});
|
|
|
} catch (Exception e) {
|
|
@@ -97,9 +95,8 @@ public class CatMongoInterceptInvoke implements MongoInterceptInvoke {
|
|
|
String queryList = "QueryList";
|
|
|
String type = String.format("%s - %s", collectionName, queryList);
|
|
|
return CatCrossProcess.processTransactionMsg("mongodb", type, (t) -> {
|
|
|
- logger.debug(" field : {} ", getString(query));
|
|
|
+ logger.debug(" query : {} ", getString(query));
|
|
|
logger.debug(" field : {} ", getString(fields));
|
|
|
- logger.info("---------->>>>>>>>>>>>>>>" + Cat.getCurrentMessageId());
|
|
|
List<T> executor = chain.executor(request, MongoInterceptInvoke::queryList);
|
|
|
logger.info("mongo result size : {} ", executor.size());
|
|
|
return executor;
|
|
@@ -123,9 +120,8 @@ public class CatMongoInterceptInvoke implements MongoInterceptInvoke {
|
|
|
return CatCrossProcess.processTransactionMsg("mongodb", type, (t) -> {
|
|
|
logger.debug(" query : {}", getString(query));
|
|
|
logger.debug(" field : {} ", getString(fields));
|
|
|
- logger.info("---------->>>>>>>>>>>>>>>" + Cat.getCurrentMessageId());
|
|
|
T executor = chain.executor(request, MongoInterceptInvoke::queryOne);
|
|
|
- logger.info("mongo result : {}", getJsonString(executor));
|
|
|
+ logger.info("mongo result : {}", LogUtils.getJsonString(executor));
|
|
|
return executor;
|
|
|
});
|
|
|
} catch (Exception e) {
|
|
@@ -141,23 +137,4 @@ public class CatMongoInterceptInvoke implements MongoInterceptInvoke {
|
|
|
return obj.toString();
|
|
|
}
|
|
|
|
|
|
- private String getJsonString(Object obj) {
|
|
|
- if (obj == null) {
|
|
|
- return "";
|
|
|
- } else if (obj instanceof String) {
|
|
|
- return (String)obj;
|
|
|
- }
|
|
|
- try {
|
|
|
- int maxLength = 1000;
|
|
|
- String result = JSON.toJSONString(obj);
|
|
|
- // 优化日志输出
|
|
|
- if (result.length() > maxLength) {
|
|
|
- return result.substring(0, maxLength);
|
|
|
- }
|
|
|
- return result;
|
|
|
- } catch (Exception e) {
|
|
|
- logger.warn("格式转换异常:{}", e.getMessage());
|
|
|
- }
|
|
|
- return "";
|
|
|
- }
|
|
|
}
|