51 lines
1.7 KiB
Java
51 lines
1.7 KiB
Java
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;
|
|
import java.io.FileNotFoundException;
|
|
import java.text.SimpleDateFormat;
|
|
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) {
|
|
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);
|
|
}
|
|
}
|
|
|
|
}
|