日志
This commit is contained in:
parent
cb0d4e6e9f
commit
63c663a88f
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,3 +1,5 @@
|
|||||||
/.idea/
|
/.idea/
|
||||||
/target/
|
/target/
|
||||||
/pack/
|
/pack/
|
||||||
|
/logs/
|
||||||
|
/test-log/
|
||||||
|
|||||||
Binary file not shown.
20
kit.json
20
kit.json
@ -5,7 +5,7 @@
|
|||||||
},
|
},
|
||||||
"clear": [
|
"clear": [
|
||||||
{
|
{
|
||||||
"func": "rmdir",
|
"func": "rm",
|
||||||
"path": "%out_path%"
|
"path": "%out_path%"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
@ -31,6 +31,12 @@
|
|||||||
"cmd" : "dproto"
|
"cmd" : "dproto"
|
||||||
}],
|
}],
|
||||||
"build": [
|
"build": [
|
||||||
|
{
|
||||||
|
"cmd": "clear"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cmd": "init"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"shell": "mvn package -DskipTests",
|
"shell": "mvn package -DskipTests",
|
||||||
"check": "BUILD SUCCESS"
|
"check": "BUILD SUCCESS"
|
||||||
@ -49,9 +55,19 @@
|
|||||||
"from": "./doc",
|
"from": "./doc",
|
||||||
"to": "%out_path%/doc"
|
"to": "%out_path%/doc"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"func": "cp",
|
||||||
|
"from": "./src/test/java/sample",
|
||||||
|
"to": "%out_path%/sample"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"func": "zip",
|
"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"
|
"to": "%out_path%/sydapi-%version%.%project.git_commit_hash%.zip"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
7
pom.xml
7
pom.xml
@ -28,7 +28,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.sunyard</groupId>
|
<groupId>com.sunyard</groupId>
|
||||||
<artifactId>sydapi4j</artifactId>
|
<artifactId>sydapi4j</artifactId>
|
||||||
<version>1.0.20220712</version>
|
<version>1.0.20220722</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
@ -46,11 +46,6 @@
|
|||||||
<artifactId>log4j-slf4j-impl</artifactId>
|
<artifactId>log4j-slf4j-impl</artifactId>
|
||||||
<version>${log.version}</version>
|
<version>${log.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency> <!-- 桥接:告诉commons logging使用Log4j2 -->
|
|
||||||
<groupId>org.apache.logging.log4j</groupId>
|
|
||||||
<artifactId>log4j-jcl</artifactId>
|
|
||||||
<version>${log.version}</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|||||||
@ -5,6 +5,12 @@ public class Consts {
|
|||||||
public static final int ECB_ENC = 1;
|
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;
|
public static final int PkgNumAll = 0;
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,9 @@
|
|||||||
package com.sunyard.sge.database;
|
package com.sunyard.sge.database;
|
||||||
|
|
||||||
|
import com.sunyard.sge.log.LogFactory;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import racal.sunyard.main.SydApi4j;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -23,6 +27,8 @@ public interface SydApi {
|
|||||||
String pcLogPath,
|
String pcLogPath,
|
||||||
int iLogLevel) {
|
int iLogLevel) {
|
||||||
|
|
||||||
|
Logger logger = LogFactory.createLogger(pcLogPath, iLogLevel);
|
||||||
|
SydApi4j.setLogger( logger );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -14,6 +14,14 @@ public class SydApi4Database implements SydApi {
|
|||||||
|
|
||||||
private SydApi4j[] hsms = null;
|
private SydApi4j[] hsms = null;
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
public SydApi4Database() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public SydApi4Database(SydApi4j[] hsms) {
|
||||||
|
this.hsms = hsms;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SydApi SYD_Connect_Ex(String[] pcIpList, int[] iPortList, int iConnectTimeOut, int iDealTimeOut) {
|
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);
|
SydApi4j api = (SydApi4j) new SydApi4j().connect(pcIpList[0], iPortList[0], null, iConnectTimeOut);
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
package com.sunyard.sge.database.pool;
|
package com.sunyard.sge.database.pool;
|
||||||
|
|
||||||
import com.sunyard.sge.database.SydApi;
|
import com.sunyard.sge.database.SydApi;
|
||||||
|
import com.sunyard.sge.database.SydApi4Database;
|
||||||
import com.sunyard.sge.pool.ThreadBasedConnectPool;
|
import com.sunyard.sge.pool.ThreadBasedConnectPool;
|
||||||
import racal.sunyard.main.SydApi4j;
|
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;
|
package com.sunyard.sge.log;
|
||||||
|
|
||||||
|
import com.sunyard.sge.database.Consts;
|
||||||
import org.apache.logging.log4j.Level;
|
import org.apache.logging.log4j.Level;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.core.Appender;
|
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 String logName = "sge-hsm-sydapi-log";
|
||||||
|
|
||||||
// 日志级别
|
// 日志级别
|
||||||
public static final int LogLevelOFF = 0;
|
public static int iLogLevel = Consts.LogLevelOFF;
|
||||||
public static final int LogLevelError = 1;
|
|
||||||
public static final int LogLevelInfo = 2;
|
|
||||||
public static final int LogLevelDebug = 3;
|
|
||||||
public static int iLogLevel = LogLevelDebug;
|
|
||||||
|
|
||||||
// Levels
|
// Levels
|
||||||
public static final Level[] levels = new Level[]{ Level.OFF, Level.ERROR, Level.INFO, Level.DEBUG };
|
public static final Level[] levels = new Level[]{ Level.OFF, Level.ERROR, Level.INFO, Level.DEBUG };
|
||||||
@ -100,7 +97,9 @@ public class LogFactory {
|
|||||||
* 创建 Logger
|
* 创建 Logger
|
||||||
* @return Logger
|
* @return Logger
|
||||||
*/
|
*/
|
||||||
public static Logger createLogger() {
|
public static Logger createLogger(String pcLogPath, int iLogLevel) {
|
||||||
|
LogFactory.pcLogPath = pcLogPath;
|
||||||
|
LogFactory.iLogLevel = iLogLevel;
|
||||||
start();
|
start();
|
||||||
return LoggerFactory.getLogger( logName );
|
return LoggerFactory.getLogger( logName );
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,7 +3,9 @@ package sample;
|
|||||||
import com.sunyard.proto.Util;
|
import com.sunyard.proto.Util;
|
||||||
import com.sunyard.sge.database.*;
|
import com.sunyard.sge.database.*;
|
||||||
import com.sunyard.sge.database.Consts;
|
import com.sunyard.sge.database.Consts;
|
||||||
|
import com.sunyard.sge.log.LogFactory;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -13,17 +15,31 @@ public class Sample
|
|||||||
{
|
{
|
||||||
public static void main(String[] args) {
|
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();
|
||||||
try {
|
log.info("start");
|
||||||
api = api.SYD_Connect_Ex(
|
|
||||||
|
// 通常单例就够了
|
||||||
|
SydApiBuilder builder = new SydApiBuilder(
|
||||||
new String[]{ "192.168.0.200" },
|
new String[]{ "192.168.0.200" },
|
||||||
new int[]{ 8889 },
|
new int[]{ 8889 },
|
||||||
10,
|
10,
|
||||||
15
|
15
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// 每个工作线程中调用
|
||||||
|
SydApi api = builder.build();
|
||||||
|
try {
|
||||||
|
// 不建议使用了
|
||||||
|
// api = api.SYD_Connect_Ex(
|
||||||
|
// new String[]{ "192.168.0.200" },
|
||||||
|
// new int[]{ 8889 },
|
||||||
|
// 10,
|
||||||
|
// 15
|
||||||
|
// );
|
||||||
|
|
||||||
|
|
||||||
// 短数据加密解密
|
// 短数据加密解密
|
||||||
shortEndeData( api );
|
shortEndeData( api );
|
||||||
@ -54,6 +70,8 @@ public class Sample
|
|||||||
if ( null != api ) {
|
if ( null != api ) {
|
||||||
api.SYD_Disconnect_Ex();
|
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 class LogTest {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
Logger log = LogFactory.createLogger();
|
Logger log = LogFactory.createLogger("./test-log/", 2);
|
||||||
log.error("error");
|
log.error("error");
|
||||||
log.info("info");
|
log.info("info");
|
||||||
log.debug("debug");
|
log.debug("debug");
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user