简体   繁体   English

如何使用 Ganymed SSH-2 启用完整日志记录

[英]How to enable FULL Logging with Ganymed SSH-2

I am developing a java application that executes ssh commands using Ganymed SSH-2我正在开发一个使用Ganymed SSH-2执行 ssh 命令的 Java 应用程序

I need to produce full logs for each sequence of commands, eg zip file transfer, unzipping, zipping etc..我需要为每个命令序列生成完整的日志,例如 zip 文件传输、解压缩、压缩等。

Having searched the source code for ch.ethz.ssh2.log.Logger i can set the boolean public static volatile boolean enabled = false;搜索了ch.ethz.ssh2.log.Logger的源代码后,我可以设置 boolean public static volatile boolean enabled = false; to true为真

this provides the following output这提供了以下输出

Mar 05, 2015 10:17:25 AM ch.ethz.ssh2.log.Logger info
INFO: kex_algo=diffie-hellman-group-exchange-sha1
Mar 05, 2015 10:17:25 AM ch.ethz.ssh2.log.Logger info
INFO: server_host_key_algo=ssh-rsa
Mar 05, 2015 10:17:25 AM ch.ethz.ssh2.log.Logger info
INFO: enc_algo_client_to_server=aes128-ctr
Mar 05, 2015 10:17:25 AM ch.ethz.ssh2.log.Logger info
INFO: enc_algo_server_to_client=aes128-ctr
Mar 05, 2015 10:17:25 AM ch.ethz.ssh2.log.Logger info
INFO: mac_algo_client_to_server=hmac-sha1-96
Mar 05, 2015 10:17:25 AM ch.ethz.ssh2.log.Logger info
INFO: mac_algo_server_to_client=hmac-sha1-96
Mar 05, 2015 10:17:25 AM ch.ethz.ssh2.log.Logger info
INFO: comp_algo_client_to_server=none
Mar 05, 2015 10:17:25 AM ch.ethz.ssh2.log.Logger info
INFO: comp_algo_server_to_client=none

However I also require ALL level logging for command execution including file transfers.但是,我还需要所有级别的日志记录来执行命令,包括文件传输。

How do i configure the Logger to produce all the information available?如何配置 Logger 以生成所有可用信息?

A little late answer but maybe someone still needs this info. 答案有点晚,但也许有人仍然需要此信息。

I managed to get the debug statements visible like this: 我设法使调试语句如下所示:

    public void enableFineLogging() {
    try {
        ch.ethz.ssh2.log.Logger.enabled = true;
        String name = "myDynamicFileNamePart";

        FileHandler fileHandler = new FileHandler("./logs/"
                + name + "_SFTP.log", 10000000, 1000, true);
        fileHandler.setLevel(Level.FINE);
        fileHandler.setFormatter(new SimpleFormatter());

        final Logger app = Logger.getLogger("ch.ethz");
        app.setLevel(Level.FINE);
        app.addHandler(fileHandler);
        app.setUseParentHandlers(false);

    } catch (Exception e) {
        // Catchalog
    }
}

With result in file with: 在结果文件中包含:

marras 15, 2017 12:16:56 IP. marras 15,2017 12:16:56 IP。 org.slf4j.impl.JCLLoggerAdapter info org.slf4j.impl.JCLLoggerAdapter信息

INFO: Client identity string: SSH-2.0-SSHJ_0.19.1 INFO:客户端身份字符串:SSH-2.0-SSHJ_0.19.1

marras 15, 2017 12:16:56 IP. marras 15,2017 12:16:56 IP。 org.slf4j.impl.JCLLoggerAdapter info org.slf4j.impl.JCLLoggerAdapter信息

INFO: Server identity string: SSH-2.0-OpenSSH_6.6.1 INFO:服务器标识字符串:SSH-2.0-OpenSSH_6.6.1

marras 15, 2017 12:16:56 IP. marras 15,2017 12:16:56 IP。 org.slf4j.impl.JCLLoggerAdapter debug org.slf4j.impl.JCLLoggerAdapter调试

FINE: Setting <> to null 精细:将<>设置为null

marras 15, 2017 12:16:56 IP. marras 15,2017 12:16:56 IP。 org.slf4j.impl.JCLLoggerAdapter debug org.slf4j.impl.JCLLoggerAdapter调试

FINE: Sending SSH_MSG_KEXINIT FINE:发送SSH_MSG_KEXINIT

marras 15, 2017 12:16:56 IP. marras 15,2017 12:16:56 IP。 org.slf4j.impl.JCLLoggerAdapter debug org.slf4j.impl.JCLLoggerAdapter调试

FINE: Setting <> to SOME 精细:将<>设置为SOME

marras 15, 2017 12:16:56 IP. marras 15,2017 12:16:56 IP。 org.slf4j.impl.JCLLoggerAdapter debug org.slf4j.impl.JCLLoggerAdapter调试

FINE: Awaiting <> 精细:等待<>

marras 15, 2017 12:16:56 IP. marras 15,2017 12:16:56 IP。 org.slf4j.impl.JCLLoggerAdapter debug org.slf4j.impl.JCLLoggerAdapter调试

FINE: Received SSH_MSG_KEXINIT FINE:已收到SSH_MSG_KEXINIT

Use ConsoleHandler if you wish logs in console. 如果您希望登录控制台,请使用ConsoleHandler。 Also closing the log file needs to be considered with fileHandler.close() after you quit logging. 退出日志记录后,还需要使用fileHandler.close()考虑关闭日志文件。

Tune the log level by choosing from SEVERE, WARNING, INFO, CONFIG, FINE, FINER, FINEST, ALL 通过选择SEVERE, WARNING, INFO, CONFIG, FINE, FINER, FINEST, ALL调整日志级别

I have added ganymed-ssh2 library in my application.我在我的应用程序中添加了 ganymed-ssh2 库。 My application establish SSH connection using this lib.我的应用程序使用此库建立 SSH 连接。

I set log level to ALL (app.setLevel(Level.ALL);我将日志级别设置为 ALL (app.setLevel(Level.ALL);

I called the method enableFineLogging from my application.我从我的应用程序中调用了 enableFineLogging 方法。

When I run my application, I see the log file created as specified in fileHandler.当我运行我的应用程序时,我看到按照 fileHandler 中指定的方式创建的日志文件。

But, I do not see the log file populated.但是,我没有看到填充的日志文件。 What could be the reason?可能是什么原因?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM