Skip to content

Commit 0da5faf

Browse files
committed
logging workaround for issue 10
1 parent 2cedd79 commit 0da5faf

File tree

11 files changed

+115
-160
lines changed

11 files changed

+115
-160
lines changed

plugin-core/BUILD

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,13 @@ eclipse_plugin(
1515
version = VERSION,
1616
visibility = ["//visibility:public"],
1717
# include this p2.inf entry only if you want to manually control the contents of this file, otherwise it is auto generated
18-
classpath_resources = ['META-INF/p2.inf', 'plugin.xml'],
18+
classpath_resources = ['plugin.xml'],
1919
deps = [
2020
"//plugin-libs/plugin-abstractions",
2121
"//plugin-libs/plugin-command",
2222
"//plugin-libs/plugin-model",
2323

2424
"//plugin-libs/plugin-deps:com_google_guava",
25-
"//plugin-libs/plugin-deps:org_slf4j_slf4j_api",
26-
"//plugin-libs/plugin-deps:ch_qos_logback_logback_classic",
27-
"//plugin-libs/plugin-deps:ch_qos_logback_logback_core",
2825
],
2926
)
3027

plugin-core/META-INF/MANIFEST.MF

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,7 @@ Import-Package: com.salesforce.bazel.eclipse.abstractions;version="1.1.0.qualifi
3535
com.salesforce.bazel.eclipse.command;version="1.1.0.qualifier",
3636
com.salesforce.bazel.eclipse.logging;version="1.1.0.qualifier",
3737
com.salesforce.bazel.eclipse.model;version="1.1.0.qualifier",
38-
ch.qos.logback.classic;version="1.0.7",
39-
ch.qos.logback.classic.joran;version="1.0.7",
40-
ch.qos.logback.core;version="1.0.7",
41-
ch.qos.logback.core.joran;version="1.0.7",
42-
ch.qos.logback.core.joran.spi;version="1.0.7",
43-
ch.qos.logback.core.spi;version="1.0.7",
4438
com.google.common.base;version="21.0",
45-
com.google.common.collect;version="21.0",
46-
org.slf4j;version="1.7.7",
47-
org.slf4j.helpers;version="1.7.7"
39+
com.google.common.collect;version="21.0"
4840
Export-Package: com.salesforce.bazel.eclipse;version="1.1.0.qualifier",
4941
com.salesforce.bazel.eclipse.launch;version="1.1.0.qualifier"

plugin-core/src/main/java/com/salesforce/bazel/eclipse/EclipseLoggerFacade.java

Lines changed: 62 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -35,39 +35,19 @@
3535
*/
3636
package com.salesforce.bazel.eclipse;
3737

38-
import java.io.File;
39-
import java.io.IOException;
40-
import java.net.URL;
41-
42-
import org.eclipse.core.resources.ResourcesPlugin;
43-
import org.eclipse.core.runtime.FileLocator;
44-
import org.eclipse.core.runtime.ILog;
45-
import org.eclipse.core.runtime.IPath;
46-
import org.eclipse.core.runtime.Path;
47-
import org.eclipse.core.runtime.Platform;
48-
import org.eclipse.core.runtime.Status;
4938
import org.osgi.framework.Bundle;
50-
import org.osgi.framework.FrameworkUtil;
51-
import org.slf4j.ILoggerFactory;
52-
import org.slf4j.LoggerFactory;
53-
import org.slf4j.helpers.MessageFormatter;
5439

40+
import com.salesforce.bazel.eclipse.logging.BasicLoggerFacade;
5541
import com.salesforce.bazel.eclipse.logging.LoggerFacade;
56-
import com.salesforce.bazel.eclipse.logging.Slf4jLoggerFacade;
57-
58-
import ch.qos.logback.classic.LoggerContext;
59-
import ch.qos.logback.classic.joran.JoranConfigurator;
60-
import ch.qos.logback.core.joran.spi.JoranException;
6142

6243
/**
6344
* Add Eclipse Platform logging to WARN and ERROR log messages as well as slf4j logging api.
64-
*
65-
* @author Blaine Buxton
66-
*
45+
* <p>
46+
* TODO we will revisit this logging feature later, see https://github.com/salesforce/bazel-eclipse/issues/10
6747
*/
68-
public class EclipseLoggerFacade extends Slf4jLoggerFacade {
69-
private static final Bundle BUNDLE = FrameworkUtil.getBundle(EclipseLoggerFacade.class);
70-
private static final ILog LOG = Platform.getLog(BUNDLE);
48+
public class EclipseLoggerFacade extends BasicLoggerFacade {
49+
//private static final Bundle BUNDLE = FrameworkUtil.getBundle(EclipseLoggerFacade.class);
50+
// private static final ILog LOG = Platform.getLog(BUNDLE);
7151

7252
/**
7353
* Install the facade as the singleton and configure logging system
@@ -77,8 +57,8 @@ public class EclipseLoggerFacade extends Slf4jLoggerFacade {
7757
*/
7858
public static void install(Bundle bundle) throws Exception {
7959
EclipseLoggerFacade instance = new EclipseLoggerFacade();
80-
LoggerFacade.setInstance(new EclipseLoggerFacade());
81-
instance.configureLogging(bundle);
60+
LoggerFacade.setInstance(instance);
61+
//instance.configureLogging(bundle);
8262
}
8363

8464
/**
@@ -89,22 +69,22 @@ private EclipseLoggerFacade() {}
8969
@Override
9070
public void error(Class<?> from, String message, Object... args) {
9171
super.error(from, message, args);
92-
String resolved = MessageFormatter.arrayFormat(message, args).getMessage();
93-
LOG.log(new Status(Status.ERROR, BUNDLE.getSymbolicName(), resolved));
72+
//String resolved = MessageFormatter.arrayFormat(message, args).getMessage();
73+
//LOG.log(new Status(Status.ERROR, BUNDLE.getSymbolicName(), resolved));
9474
}
9575

9676
@Override
9777
public void error(Class<?> from, String message, Throwable exception, Object... args) {
9878
super.error(from, message, exception, args);
99-
String resolved = MessageFormatter.arrayFormat(message, args).getMessage();
100-
LOG.log(new Status(Status.ERROR, BUNDLE.getSymbolicName(), resolved, exception));
79+
//String resolved = MessageFormatter.arrayFormat(message, args).getMessage();
80+
//LOG.log(new Status(Status.ERROR, BUNDLE.getSymbolicName(), resolved, exception));
10181
}
10282

10383
@Override
10484
public void warn(Class<?> from, String message, Object... args) {
10585
super.warn(from, message, args);
106-
String resolved = MessageFormatter.arrayFormat(message, args).getMessage();
107-
LOG.log(new Status(Status.INFO, BUNDLE.getSymbolicName(), resolved));
86+
//String resolved = MessageFormatter.arrayFormat(message, args).getMessage();
87+
//LOG.log(new Status(Status.INFO, BUNDLE.getSymbolicName(), resolved));
10888
}
10989

11090
/**
@@ -114,55 +94,55 @@ public void warn(Class<?> from, String message, Object... args) {
11494
* @throws JoranException
11595
* @throws IOException
11696
*/
117-
private void configureLogging(Bundle bundle) throws JoranException, IOException {
97+
// private void configureLogging(Bundle bundle) throws JoranException, IOException {
11898
// capture the logger context, but guard against:
11999
// org.slf4j.helpers.NOPLoggerFactory cannot be cast to ch.qos.logback.classic.LoggerContext
120-
ILoggerFactory iFactory = LoggerFactory.getILoggerFactory();
121-
if (iFactory instanceof LoggerContext) {
122-
LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
123-
JoranConfigurator jc = new JoranConfigurator();
124-
jc.setContext(context);
125-
context.reset();
126-
127-
IPath pluginPath = ResourcesPlugin.getPlugin().getStateLocation();
128-
String logFile = new File(pluginPath.toFile(), bundle.getSymbolicName().replace('.', '_') + ".log")
129-
.getAbsolutePath();
130-
context.putProperty("logFile", logFile);
131-
eclipseOnlyInfo("Debug log file: {}", logFile);
132-
133-
URL logbackConfig = FileLocator.find(bundle, new Path("logback.xml"), null);
134-
if (null == logbackConfig) {
135-
//not found log an event to the error log
136-
error(getClass(), "logback.xml not found. All slf4j output to console");
137-
}
138-
jc.doConfigure(logbackConfig);
139-
} else {
140-
// Logback was missing from the classpath when logging was initialized for some reason
141-
142-
// check classloader to see if it is there now (if it is, there must be a load order issue?)
143-
String isLoggerContextIsInClasspathStr =
144-
"The class ch.qos.logback.classic.LoggerContext is not present in the classpath which means the plugin never imported it.";
145-
try {
146-
Class.forName("ch.qos.logback.classic.LoggerContext");
147-
isLoggerContextIsInClasspathStr =
148-
"The class ch.qos.logback.classic.LoggerContext is NOW available in the classpath, which means there was a startup loading issue. The class wasn't there when logging was initialized.";
149-
} catch (Exception cnfe) {}
150-
151-
System.err.println(
152-
"com.salesforce.bazel.eclipse.core: EclipseLoggerFacade could not configure file (INFO, DEBUG) logging. LoggerFactory is of type ["
153-
+ iFactory.getClass()
154-
+ "] but needed [ch.qos.logback.classic.LoggerContext] to configure the file log. "
155-
+ isLoggerContextIsInClasspathStr + " See "
156-
+ "bazel-eclipse/docs/dev/logging.md for more details.");
157-
158-
// set the activator convenience methods to log to sys err
159-
BazelPluginActivator.logToSystemErr();
160-
}
161-
}
162-
163-
private void eclipseOnlyInfo(String message, Object... args) {
164-
String resolved = MessageFormatter.arrayFormat(message, args).getMessage();
165-
LOG.log(new Status(Status.INFO, BUNDLE.getSymbolicName(), resolved));
166-
}
100+
// ILoggerFactory iFactory = LoggerFactory.getILoggerFactory();
101+
// if (iFactory instanceof LoggerContext) {
102+
// LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
103+
// JoranConfigurator jc = new JoranConfigurator();
104+
// jc.setContext(context);
105+
// context.reset();
106+
//
107+
// IPath pluginPath = ResourcesPlugin.getPlugin().getStateLocation();
108+
// String logFile = new File(pluginPath.toFile(), bundle.getSymbolicName().replace('.', '_') + ".log")
109+
// .getAbsolutePath();
110+
// context.putProperty("logFile", logFile);
111+
// eclipseOnlyInfo("Debug log file: {}", logFile);
112+
//
113+
// URL logbackConfig = FileLocator.find(bundle, new Path("logback.xml"), null);
114+
// if (null == logbackConfig) {
115+
// //not found log an event to the error log
116+
// error(getClass(), "logback.xml not found. All slf4j output to console");
117+
// }
118+
// jc.doConfigure(logbackConfig);
119+
// } else {
120+
// // Logback was missing from the classpath when logging was initialized for some reason
121+
//
122+
// // check classloader to see if it is there now (if it is, there must be a load order issue?)
123+
// String isLoggerContextIsInClasspathStr =
124+
// "The class ch.qos.logback.classic.LoggerContext is not present in the classpath which means the plugin never imported it.";
125+
// try {
126+
// Class.forName("ch.qos.logback.classic.LoggerContext");
127+
// isLoggerContextIsInClasspathStr =
128+
// "The class ch.qos.logback.classic.LoggerContext is NOW available in the classpath, which means there was a startup loading issue. The class wasn't there when logging was initialized.";
129+
// } catch (Exception cnfe) {}
130+
//
131+
// System.err.println(
132+
// "com.salesforce.bazel.eclipse.core: EclipseLoggerFacade could not configure file (INFO, DEBUG) logging. LoggerFactory is of type ["
133+
// + iFactory.getClass()
134+
// + "] but needed [ch.qos.logback.classic.LoggerContext] to configure the file log. "
135+
// + isLoggerContextIsInClasspathStr + " See "
136+
// + "bazel-eclipse/docs/dev/logging.md for more details.");
137+
//
138+
// // set the activator convenience methods to log to sys err
139+
// BazelPluginActivator.logToSystemErr();
140+
// }
141+
// }
142+
143+
// private void eclipseOnlyInfo(String message, Object... args) {
144+
// String resolved = MessageFormatter.arrayFormat(message, args).getMessage();
145+
// LOG.log(new Status(Status.INFO, BUNDLE.getSymbolicName(), resolved));
146+
// }
167147

168148
}

plugin-libs/plugin-command/META-INF/MANIFEST.MF

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ Import-Package: com.google.common.base,
1111
com.google.common.collect,
1212
com.salesforce.bazel.eclipse.abstractions;version="1.1.0.qualifier",
1313
com.salesforce.bazel.eclipse.logging;version="1.1.0.qualifier",
14-
com.salesforce.bazel.eclipse.model;version="1.1.0.qualifier",
15-
org.slf4j
14+
com.salesforce.bazel.eclipse.model;version="1.1.0.qualifier"
1615
Bundle-Vendor: Salesforce
1716
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
1817
Bundle-ActivationPolicy: lazy

plugin-libs/plugin-deps/.classpath

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,5 @@
88
</classpathentry>
99
<classpathentry exported="true" kind="lib" path="lib/guava-21.0.jar"/>
1010
<classpathentry exported="true" kind="lib" path="lib/json-20160212.jar"/>
11-
<classpathentry exported="true" kind="lib" path="lib/slf4j-api-1.7.7.jar"/>
12-
<classpathentry exported="true" kind="lib" path="lib/logback-core-1.0.7.jar"/>
13-
<classpathentry exported="true" kind="lib" path="lib/logback-classic-1.0.7.jar"/>
1411
<classpathentry kind="output" path="bin"/>
1512
</classpath>

plugin-libs/plugin-deps/BUILD

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -25,36 +25,35 @@ java_import(
2525
],
2626
)
2727

28-
# SLF4J-API is a weird one. It comes along for free in the Eclipse SDK
29-
java_import(
30-
name = "org_slf4j_slf4j_api",
31-
jars = [
32-
"lib/slf4j-api-1.7.7.jar",
33-
],
34-
visibility = [
35-
"//visibility:public",
36-
],
37-
)
28+
#java_import(
29+
# name = "org_slf4j_slf4j_api",
30+
# jars = [
31+
# "lib/slf4j-api-1.7.7.jar",
32+
# ],
33+
# visibility = [
34+
# "//visibility:public",
35+
# ],
36+
#)
3837

39-
java_import(
40-
name = "ch_qos_logback_logback_core",
41-
jars = [
42-
"lib/logback-core-1.0.7.jar",
43-
],
44-
visibility = [
45-
"//visibility:public",
46-
],
47-
)
38+
#java_import(
39+
# name = "ch_qos_logback_logback_core",
40+
# jars = [
41+
# "lib/logback-core-1.0.7.jar",
42+
# ],
43+
# visibility = [
44+
# "//visibility:public",
45+
# ],
46+
#)
4847

49-
java_import(
50-
name = "ch_qos_logback_logback_classic",
51-
jars = [
52-
"lib/logback-classic-1.0.7.jar",
53-
],
54-
visibility = [
55-
"//visibility:public",
56-
],
57-
)
48+
#java_import(
49+
# name = "ch_qos_logback_logback_classic",
50+
# jars = [
51+
# "lib/logback-classic-1.0.7.jar",
52+
# ],
53+
# visibility = [
54+
# "//visibility:public",
55+
# ],
56+
#)
5857

5958
eclipse_plugin(
6059
name = "com.salesforce.bazel.eclipse.deps",
@@ -67,6 +66,5 @@ eclipse_plugin(
6766
deps = [
6867
":com_google_guava",
6968
":org_json_json",
70-
":org_slf4j_slf4j_api",
7169
],
7270
)

plugin-libs/plugin-deps/META-INF/MANIFEST.MF

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,7 @@ Bundle-Vendor: Salesforce
88
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
99
Bundle-ActivationPolicy: lazy
1010
Bundle-ClassPath: lib/guava-21.0.jar,
11-
lib/json-20160212.jar,
12-
lib/logback-classic-1.0.7.jar,
13-
lib/logback-core-1.0.7.jar,
14-
lib/slf4j-api-1.7.7.jar
15-
Export-Package: ch.qos.logback.classic;version="1.0.7",
16-
ch.qos.logback.classic.joran;version="1.0.7",
17-
ch.qos.logback.core;version="1.0.7",
18-
ch.qos.logback.core.joran;version="1.0.7",
19-
ch.qos.logback.core.joran.spi;version="1.0.7",
20-
ch.qos.logback.core.spi;version="1.0.7",
21-
com.google.common.base;version="21.0",
11+
lib/json-20160212.jar
12+
Export-Package: com.google.common.base;version="21.0",
2213
com.google.common.collect;version="21.0",
23-
org.json;version="20160212",
24-
org.slf4j;version="1.7.7",
25-
org.slf4j.helpers;version="1.7.7"
14+
org.json;version="20160212"

plugin-libs/plugin-model/BUILD

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ java_library(
1616

1717
"//plugin-libs/plugin-deps:com_google_guava",
1818
"//plugin-libs/plugin-deps:org_json_json",
19-
"//plugin-libs/plugin-deps:org_slf4j_slf4j_api",
2019
],
2120
)
2221

@@ -31,7 +30,6 @@ eclipse_plugin(
3130
deps = [
3231
"//plugin-libs/plugin-deps:com_google_guava",
3332
"//plugin-libs/plugin-deps:org_json_json",
34-
"//plugin-libs/plugin-deps:org_slf4j_slf4j_api",
3533
],
3634
)
3735

plugin-libs/plugin-model/META-INF/MANIFEST.MF

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ Export-Package: com.salesforce.bazel.eclipse.model;version="1.1.0.qualifier",
99
Import-Package: com.google.common.base,
1010
com.google.common.collect,
1111
com.salesforce.bazel.eclipse.logging,
12-
org.json,
13-
org.slf4j
12+
org.json
1413
Bundle-Vendor: Salesforce
1514
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
1615
Bundle-ActivationPolicy: lazy

0 commit comments

Comments
 (0)