Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Wolf2018-05-14 17:32:01 -0400
committerMatthias Sohn2018-05-28 18:54:08 -0400
commit2a6168830888138266c0e199622abd5ddf2cd236 (patch)
tree5bac762795dcbb748bf979d52996553de919ebd6
parentc4a3e2b6f8c03bc4d980aac8c616218b457a870f (diff)
downloadegit-2a6168830888138266c0e199622abd5ddf2cd236.tar.gz
egit-2a6168830888138266c0e199622abd5ddf2cd236.tar.xz
egit-2a6168830888138266c0e199622abd5ddf2cd236.zip
Add tracing of low-level JSch log messages
Currently there is no way in Eclipse to get hold of the log messages JSch produces. But those might be useful to analyze connection problems. So add debug logging via the OSGi debug trace mechanism; a user can switch this on by enabling tracing in the preferences (Preferences->General->Tracing) and then setting the flags for org.eclipse.egit.core/debug and org.eclipse.egit.core/debug/core/jsch to true. Change-Id: I4c9befbca0330671050fae60efafd72d9925825e Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
-rw-r--r--org.eclipse.egit.core/.options2
-rw-r--r--org.eclipse.egit.core/src/org/eclipse/egit/core/EclipseSshSessionFactory.java3
-rw-r--r--org.eclipse.egit.core/src/org/eclipse/egit/core/internal/trace/GitTraceLocation.java4
-rw-r--r--org.eclipse.egit.core/src/org/eclipse/egit/core/internal/trace/JSchLogger.java49
4 files changed, 57 insertions, 1 deletions
diff --git a/org.eclipse.egit.core/.options b/org.eclipse.egit.core/.options
index 4b25aa4c4..2a7697f7c 100644
--- a/org.eclipse.egit.core/.options
+++ b/org.eclipse.egit.core/.options
@@ -4,4 +4,6 @@ org.eclipse.egit.core/debug = false
org.eclipse.egit.core/debug/core = false
# Trace location for the IndexDiffCache
org.eclipse.egit.core/debug/core/indexdiffcache = false
+# Trace location forJSch
+org.eclipse.egit.core/debug/core/jsch = false
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/EclipseSshSessionFactory.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/EclipseSshSessionFactory.java
index 43dd9366e..f68a6c507 100644
--- a/org.eclipse.egit.core/src/org/eclipse/egit/core/EclipseSshSessionFactory.java
+++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/EclipseSshSessionFactory.java
@@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.egit.core;
+import org.eclipse.egit.core.internal.trace.JSchLogger;
import org.eclipse.jgit.transport.CredentialsProvider;
import org.eclipse.jgit.transport.CredentialsProviderUserInfo;
import org.eclipse.jgit.transport.JschConfigSessionFactory;
@@ -23,6 +24,7 @@ import com.jcraft.jsch.Session;
import com.jcraft.jsch.UserInfo;
class EclipseSshSessionFactory extends JschConfigSessionFactory {
+
private final IJSchService provider;
EclipseSshSessionFactory(final IJSchService p) {
@@ -36,6 +38,7 @@ class EclipseSshSessionFactory extends JschConfigSessionFactory {
// our parent class in case non-default JSch instances need to be made.
//
provider.createSession("127.0.0.1", 0, "eclipse"); //$NON-NLS-1$ //$NON-NLS-2$
+ JSch.setLogger(new JSchLogger());
return provider.getJSch();
}
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/trace/GitTraceLocation.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/trace/GitTraceLocation.java
index c74aa3be7..c8c97a594 100644
--- a/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/trace/GitTraceLocation.java
+++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/trace/GitTraceLocation.java
@@ -22,7 +22,9 @@ public enum GitTraceLocation implements ITraceLocation {
/** Core */
CORE("/debug/core"), //$NON-NLS-1$
/** IndexDiffCache */
- INDEXDIFFCACHE("/debug/core/indexdiffcache"); //$NON-NLS-1$
+ INDEXDIFFCACHE("/debug/core/indexdiffcache"), //$NON-NLS-1$
+ /** JSch logging */
+ JSCH("/debug/core/jsch"); //$NON-NLS-1$
/**
* Initialize the locations
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/trace/JSchLogger.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/trace/JSchLogger.java
new file mode 100644
index 000000000..a9c0472b5
--- /dev/null
+++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/trace/JSchLogger.java
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * Copyright (c) 2018 Thomas Wolf <thomas.wolf@paranor.ch>
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+package org.eclipse.egit.core.internal.trace;
+
+import com.jcraft.jsch.Logger;
+
+/**
+ * Simple low-level logger for JSch using an OSGi debug trace; intended for
+ * analyzing Jsch connection problems.
+ */
+public class JSchLogger implements Logger {
+
+ @Override
+ public boolean isEnabled(int level) {
+ return GitTraceLocation.JSCH.isActive();
+ }
+
+ @Override
+ public void log(int level, String message) {
+ if (isEnabled(level)) {
+ GitTraceLocation.getTrace().trace(
+ GitTraceLocation.JSCH.getLocation(),
+ levelToString(level) + ": " + message); //$NON-NLS-1$
+ }
+ }
+
+ private String levelToString(int level) {
+ switch (level) {
+ case 0:
+ return "DEBUG"; //$NON-NLS-1$
+ case 1:
+ return "INFO"; //$NON-NLS-1$
+ case 2:
+ return "WARN"; //$NON-NLS-1$
+ case 3:
+ return "ERROR"; //$NON-NLS-1$
+ case 4:
+ return "FATAL"; //$NON-NLS-1$
+ default:
+ return "UNKNOWN(" + level + ')'; //$NON-NLS-1$
+ }
+ }
+} \ No newline at end of file

Back to the top