客户端 fixbug 开启上传日志功能
This commit is contained in:
@@ -2,6 +2,8 @@ package com.sv.intergration;
|
||||
|
||||
import com.jcraft.jsch.*;
|
||||
import com.sv.netty.config.NettyConstant;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
@@ -11,30 +13,37 @@ import java.util.Date;
|
||||
|
||||
public class LogService {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(LogService.class);
|
||||
|
||||
private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||
|
||||
static Session session;
|
||||
|
||||
public void uploadLog(String password) throws JSchException, FileNotFoundException, SftpException {
|
||||
if (session == null){
|
||||
JSch jsch = new JSch();
|
||||
String serverIp = System.getProperty(NettyConstant.VENUE_SERVER_IP);
|
||||
session = jsch.getSession("root", serverIp, 22);
|
||||
session.setPassword(System.getProperty(NettyConstant.VENUE_CHECK_PWD));
|
||||
session.setConfig("StrictHostKeyChecking", "no");
|
||||
session.connect(3000);
|
||||
}
|
||||
ChannelSftp sftp = (ChannelSftp) session.openChannel("sftp");
|
||||
File file = new File("/home/venue/logs/common-default.log");
|
||||
if (file.exists()){
|
||||
sftp.put(new FileInputStream(file),"/home/uploadlog/" + System.getProperty(NettyConstant.VENUE_CLIENT_SN) + "-" + sdf.format(new Date()) + "-client.log");
|
||||
}
|
||||
if (sftp != null) {
|
||||
sftp.connect();
|
||||
sftp.disconnect();
|
||||
}
|
||||
if (session != null) {
|
||||
session.disconnect();
|
||||
public void uploadLog(String password) {
|
||||
try {
|
||||
if (session == null) {
|
||||
JSch jsch = new JSch();
|
||||
String serverIp = System.getProperty(NettyConstant.VENUE_SERVER_IP);
|
||||
session = jsch.getSession("root", serverIp, 22);
|
||||
session.setPassword(System.getProperty(NettyConstant.VENUE_CHECK_PWD));
|
||||
session.setConfig("StrictHostKeyChecking", "no");
|
||||
session.connect(3000);
|
||||
}
|
||||
ChannelSftp sftp = (ChannelSftp) session.openChannel("sftp");
|
||||
File file = new File("/home/venue/logs/common-default.log");
|
||||
if (file.exists()) {
|
||||
sftp.put(new FileInputStream(file), "/home/uploadlog/" + System.getProperty(NettyConstant.VENUE_CLIENT_SN) + "-" + sdf.format(new Date()) + "-client.log");
|
||||
logger.info("上传日志成功");
|
||||
}
|
||||
if (sftp != null) {
|
||||
sftp.connect();
|
||||
sftp.disconnect();
|
||||
}
|
||||
if (session != null) {
|
||||
session.disconnect();
|
||||
}
|
||||
}catch (Exception e){
|
||||
logger.error("上传日志失败",e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user