Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Java System logger to the jsch instance
Shift log level to less serious level - Jsch issues a lot of INFO messages which are rather DEBUG level and warnings, which are rather info level Signed-off-by:Ondro Mihalyi <mihalyi@omnifish.ee>
- Loading branch information
Showing
3 changed files
with
73 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
...us/cluster/ssh/src/main/java/org/glassfish/cluster/ssh/launcher/JavaSystemJschLogger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Copyright (c) 2023 Contributors to the Eclipse Foundation | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0, which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the | ||
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License, | ||
* version 2 with the GNU Classpath Exception, which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
*/ | ||
package org.glassfish.cluster.ssh.launcher; | ||
|
||
import com.jcraft.jsch.JSch; | ||
import java.lang.System.Logger; | ||
import java.lang.System.Logger.Level; | ||
|
||
public class JavaSystemJschLogger implements com.jcraft.jsch.Logger { | ||
|
||
private final Logger logger; | ||
|
||
public JavaSystemJschLogger() { | ||
this.logger = System.getLogger(JSch.class.getName()); | ||
} | ||
|
||
public JavaSystemJschLogger(String loggerName) { | ||
this.logger = System.getLogger(loggerName); | ||
} | ||
|
||
@Override | ||
public boolean isEnabled(int jschLevel) { | ||
return logger.isLoggable(getSystemLoggerLevel(jschLevel)); | ||
} | ||
|
||
@Override | ||
public void log(int jschLevel, String message) { | ||
logger.log(getSystemLoggerLevel(jschLevel), message); | ||
} | ||
|
||
@Override | ||
public void log(int jschLevel, String message, Throwable cause) { | ||
if (cause != null) { | ||
logger.log(getSystemLoggerLevel(jschLevel), message, cause); | ||
} else { | ||
logger.log(getSystemLoggerLevel(jschLevel), message); | ||
} | ||
} | ||
|
||
static Level getSystemLoggerLevel(int jschLevel) { | ||
switch (jschLevel) { | ||
case DEBUG: | ||
return Level.TRACE; | ||
case INFO: | ||
return Level.DEBUG; | ||
case WARN: | ||
return Level.INFO; | ||
case ERROR: | ||
return Level.WARNING; | ||
case FATAL: | ||
return Level.ERROR; | ||
default: | ||
return Level.TRACE; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters