This commit is contained in:
cheney
2022-07-22 21:11:23 +08:00
parent cb0d4e6e9f
commit 63c663a88f
12 changed files with 77 additions and 25 deletions
@@ -5,6 +5,12 @@ public class Consts {
public static final int ECB_ENC = 1;
public static final int LogLevelOFF = 0;
public static final int LogLevelError = 1;
public static final int LogLevelInfo = 2;
public static final int LogLevelDebug = 3;
// 唯一包
public static final int PkgNumAll = 0;
@@ -1,5 +1,9 @@
package com.sunyard.sge.database;
import com.sunyard.sge.log.LogFactory;
import org.slf4j.Logger;
import racal.sunyard.main.SydApi4j;
import java.util.List;
/**
@@ -23,6 +27,8 @@ public interface SydApi {
String pcLogPath,
int iLogLevel) {
Logger logger = LogFactory.createLogger(pcLogPath, iLogLevel);
SydApi4j.setLogger( logger );
}
/**
@@ -14,6 +14,14 @@ public class SydApi4Database implements SydApi {
private SydApi4j[] hsms = null;
@Deprecated
public SydApi4Database() {
}
public SydApi4Database(SydApi4j[] hsms) {
this.hsms = hsms;
}
@Override
public SydApi SYD_Connect_Ex(String[] pcIpList, int[] iPortList, int iConnectTimeOut, int iDealTimeOut) {
SydApi4j api = (SydApi4j) new SydApi4j().connect(pcIpList[0], iPortList[0], null, iConnectTimeOut);
@@ -1,6 +1,7 @@
package com.sunyard.sge.database.pool;
import com.sunyard.sge.database.SydApi;
import com.sunyard.sge.database.SydApi4Database;
import com.sunyard.sge.pool.ThreadBasedConnectPool;
import racal.sunyard.main.SydApi4j;
@@ -36,7 +37,7 @@ public class SydApiPool extends ThreadBasedConnectPool<SydApi> {
}
}
return null;
return new SydApi4Database( apis );
}
// 保活接口
@@ -1,5 +1,6 @@
package com.sunyard.sge.log;
import com.sunyard.sge.database.Consts;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.Appender;
@@ -27,11 +28,7 @@ public class LogFactory {
public static final String logName = "sge-hsm-sydapi-log";
// 日志级别
public static final int LogLevelOFF = 0;
public static final int LogLevelError = 1;
public static final int LogLevelInfo = 2;
public static final int LogLevelDebug = 3;
public static int iLogLevel = LogLevelDebug;
public static int iLogLevel = Consts.LogLevelOFF;
// Levels
public static final Level[] levels = new Level[]{ Level.OFF, Level.ERROR, Level.INFO, Level.DEBUG };
@@ -100,7 +97,9 @@ public class LogFactory {
* 创建 Logger
* @return Logger
*/
public static Logger createLogger() {
public static Logger createLogger(String pcLogPath, int iLogLevel) {
LogFactory.pcLogPath = pcLogPath;
LogFactory.iLogLevel = iLogLevel;
start();
return LoggerFactory.getLogger( logName );
}
+26 -8
View File
@@ -3,7 +3,9 @@ package sample;
import com.sunyard.proto.Util;
import com.sunyard.sge.database.*;
import com.sunyard.sge.database.Consts;
import com.sunyard.sge.log.LogFactory;
import org.junit.Assert;
import org.slf4j.Logger;
import java.nio.ByteBuffer;
import java.util.ArrayList;
@@ -13,16 +15,30 @@ public class Sample
{
public static void main(String[] args) {
System.setProperty("com.sunyard.sydapi4j.debug", "true");
// 路径要以 / 或 \\ 结尾表示目录
SydApi.SYD_SetLogConfig("./logs/", Consts.LogLevelDebug );
SydApi api = new SydApi4Database();
Logger log = LogFactory.getLogger();
log.info("start");
// 通常单例就够了
SydApiBuilder builder = new SydApiBuilder(
new String[]{ "192.168.0.200" },
new int[]{ 8889 },
10,
15
);
// 每个工作线程中调用
SydApi api = builder.build();
try {
api = api.SYD_Connect_Ex(
new String[]{ "192.168.0.200" },
new int[]{ 8889 },
10,
15
);
// 不建议使用了
// api = api.SYD_Connect_Ex(
// new String[]{ "192.168.0.200" },
// new int[]{ 8889 },
// 10,
// 15
// );
// 短数据加密解密
@@ -54,6 +70,8 @@ public class Sample
if ( null != api ) {
api.SYD_Disconnect_Ex();
}
System.out.println("all over");
log.info("all over");
}
}
+1 -1
View File
@@ -6,7 +6,7 @@ import org.slf4j.Logger;
public class LogTest {
public static void main(String[] args) {
Logger log = LogFactory.createLogger();
Logger log = LogFactory.createLogger("./test-log/", 2);
log.error("error");
log.info("info");
log.debug("debug");