rookie
rookie

Reputation: 31

How to enable debug logs for j2ssh maverick?

Recently I am using j2ssh-maverick-1.5.5.jar for implementing sftp within my own java application, but I got a problem on enabling debug message via log4j.properties.

It seems it didn't work on log4j.logger.com.sshtools=DEBUG

I can find similar topic from sshtools limited: "How to enable debug logs for Maverick versions 1.4.x", but I am not using maverick-legacy-client.jar.

Could anyone tell me how can I show debug log message using j2ssh-maverick-1.5.5.jar?

Upvotes: 3

Views: 1227

Answers (2)

Simone
Simone

Reputation: 29

In j2ssh-maverick-1.5.5 you need to create a new Class that implements Logger interface. This is an example:

import com.sshtools.logging.Logger;
import com.sshtools.logging.LoggerLevel;
    
public class J2sshLogger implements Logger{
    LoggerLevel level;

    public J2sshLogger(LoggerLevel arg0) {
        level = arg0;
    }

    public boolean isLevelEnabled(LoggerLevel level) {
        return (this.level.ordinal() >= level.ordinal());
    }

    public void log(LoggerLevel level, Object source, String msg) {
        //here your log: example log.write(level, msg);
    }

    public void log(LoggerLevel level, Object source, String msg, Throwable t) {
        //here your log: example log.write(level, msg);
    }
}

When you create your SSH connection you need to set your new logger class to LoggerFactory, like this:

LoggerFactory.setInstance(new J2sshLogger(LoggerLevel.INFO));

Upvotes: 0

Lee David Painter
Lee David Painter

Reputation: 510

J2SSH Maverick uses its own logging interface Logger

But if you just want simple logging to System.out just use the SimpleLogger by calling

LoggerFactory.setInstance(new SimpleLogger(LoggerLevel.DEBUG));

Upvotes: 0

Related Questions