diff options
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 |