Skip to content

Commit

Permalink
fixing mwiede#131 issues (mwiede#134)
Browse files Browse the repository at this point in the history
* log exceptions to logger instead of STDOUT/ERR, put class under test,
fixed bugs that where found in the process

 - fixed bug in remove(String, String, String) leading to only every
second host key being removed
 - ensure that there is a SHA1-hash-instance to prevent
NullPointerExceptions
 - replaced all occurrences of STDOUT/ERR outputs in case of exceptions
with log entries
 - added a default method to Logger to allow passing the exception to be
logged with the message

* create the exception we expect to get the exception message of that
particular JVM

* use platform dependent linebreak for logging the stack trace
added log-framework-specific implementations of log(int, String,
Throwable) to pass the cause to the framework in a fitting way
added tests for all log frameworks that can be configured in a
programmatic way.

* added

* "normalize" line breaks

* enforce \r\n when printing linebreaks

* fixed test to check the line break between message and stacktrace (that
actually is system dependent)

* make members final
use slf4j 1.x API for logging to keep backward compatibility

* throw a RuntimeException (to keep the signature of KnownHost's
constructor) if the HMAC-SHA1-class can't be instantiated.
  • Loading branch information
kimmerin authored Jul 8, 2022
1 parent 793958d commit 24c803d
Show file tree
Hide file tree
Showing 10 changed files with 1,710 additions and 110 deletions.
25 changes: 21 additions & 4 deletions src/main/java/com/jcraft/jsch/JulLogger.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
package com.jcraft.jsch;

import java.util.logging.Level;
import java.util.logging.Logger;

public class JulLogger implements com.jcraft.jsch.Logger {

private static final java.util.logging.Logger logger = java.util.logging.Logger.getLogger(JSch.class.getName());
private static final Logger stlogger = Logger.getLogger(JSch.class.getName());
private final Logger logger;

public JulLogger() {
this(stlogger);
}

public JulLogger() {}
JulLogger(Logger logger) {
this.logger = logger;
}

@Override
public boolean isEnabled(int level) {
Expand All @@ -15,10 +23,19 @@ public boolean isEnabled(int level) {

@Override
public void log(int level, String message) {
logger.log(getLevel(level), message);
log(level, message, null);
}

@Override
public void log(int level, String message, Throwable cause) {
if (cause == null) {
logger.log(getLevel(level), message);
return;
}
logger.log(getLevel(level), message, cause);
}

private static Level getLevel(int level) {
static Level getLevel(int level) {
switch (level) {
case com.jcraft.jsch.Logger.DEBUG:
return Level.FINE;
Expand Down
Loading

0 comments on commit 24c803d

Please sign in to comment.