为了账号安全,请及时绑定邮箱和手机立即绑定

JSch登录文件

JSch登录文件

繁花不似锦 2019-11-03 16:04:54
我想将JSch日志保存在文件中,因为它在控制台中不显示任何内容。这是我的代码:public boolean openConnection() throws ItsSshException {    boolean connectSuccess = false;    JSch.setLogger(new MyLogger());    Properties config = new Properties();    config.put("StrictHostKeyChecking", "no");    jschSSH.setConfig(config);    try {        sshSession = jschSSH.getSession(username, hostname, port);        sshSession.setPassword(password);        sshSession.connect(connectionTimeout);        LOGGER.info("Connection timeout : " + connectionTimeout);        Thread.sleep(1000);        sshHChannel = sshSession.openChannel("shell");        sshHChannel.connect();        in = sshHChannel.getInputStream();        out = new PrintStream(sshHChannel.getOutputStream());        clearInitialSocketState();        connectSuccess = true;    } catch (Exception e) {        LOGGER.error("Error during connectiong to host: " + hostname +                     ", port: " + port + "!", e);        throw new ItsSshException("Error during connectiong to host: " + e.getMessage());    }    LOGGER.info("connectSuccess : " + connectSuccess);    return connectSuccess;}public static class MyLogger implements com.jcraft.jsch.Logger {    static java.util.Hashtable name=new java.util.Hashtable();    static{        name.put(new Integer(DEBUG), "DEBUG: ");        name.put(new Integer(INFO), "INFO: ");        name.put(new Integer(WARN), "WARN: ");        name.put(new Integer(ERROR), "ERROR: ");        name.put(new Integer(FATAL), "FATAL: ");    }    public boolean isEnabled(int level){        return true;    }    public void log(int level, String message){        System.err.print(name.get(new Integer(level)));        System.err.println(message);    }}在哪里放置jsch记录器以获取文件中的一些信息。我尝试过但从未成功:D
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 268 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信