日志
This commit is contained in:
parent
cb0d4e6e9f
commit
63c663a88f
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,3 +1,5 @@
|
||||
/.idea/
|
||||
/target/
|
||||
/pack/
|
||||
/logs/
|
||||
/test-log/
|
||||
|
||||
Binary file not shown.
20
kit.json
20
kit.json
@ -5,7 +5,7 @@
|
||||
},
|
||||
"clear": [
|
||||
{
|
||||
"func": "rmdir",
|
||||
"func": "rm",
|
||||
"path": "%out_path%"
|
||||
}
|
||||
],
|
||||
@ -31,6 +31,12 @@
|
||||
"cmd" : "dproto"
|
||||
}],
|
||||
"build": [
|
||||
{
|
||||
"cmd": "clear"
|
||||
},
|
||||
{
|
||||
"cmd": "init"
|
||||
},
|
||||
{
|
||||
"shell": "mvn package -DskipTests",
|
||||
"check": "BUILD SUCCESS"
|
||||
@ -49,9 +55,19 @@
|
||||
"from": "./doc",
|
||||
"to": "%out_path%/doc"
|
||||
},
|
||||
{
|
||||
"func": "cp",
|
||||
"from": "./src/test/java/sample",
|
||||
"to": "%out_path%/sample"
|
||||
},
|
||||
{
|
||||
"func": "zip",
|
||||
"from": "./%out_path%/*",
|
||||
"from": "%out_path%/*",
|
||||
"to": "%out_path%/sydapi-%version%.%project.git_commit_hash%.zip"
|
||||
},
|
||||
{
|
||||
"func": "open",
|
||||
"path": "%out_path%/",
|
||||
"to": "%out_path%/sydapi-%version%.%project.git_commit_hash%.zip"
|
||||
}
|
||||
]
|
||||
|
||||
7
pom.xml
7
pom.xml
@ -28,7 +28,7 @@
|
||||
<dependency>
|
||||
<groupId>com.sunyard</groupId>
|
||||
<artifactId>sydapi4j</artifactId>
|
||||
<version>1.0.20220712</version>
|
||||
<version>1.0.20220722</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
@ -46,11 +46,6 @@
|
||||
<artifactId>log4j-slf4j-impl</artifactId>
|
||||
<version>${log.version}</version>
|
||||
</dependency>
|
||||
<dependency> <!-- 桥接:告诉commons logging使用Log4j2 -->
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-jcl</artifactId>
|
||||
<version>${log.version}</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
@ -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 );
|
||||
}
|
||||
|
||||
@ -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,17 +15,31 @@ 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();
|
||||
try {
|
||||
api = api.SYD_Connect_Ex(
|
||||
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
|
||||
// );
|
||||
|
||||
|
||||
// 短数据加密解密
|
||||
shortEndeData( api );
|
||||
@ -54,6 +70,8 @@ public class Sample
|
||||
if ( null != api ) {
|
||||
api.SYD_Disconnect_Ex();
|
||||
}
|
||||
System.out.println("all over");
|
||||
log.info("all over");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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");
|
||||
|
||||
Loading…
Reference in New Issue
Block a user