Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JBIDE-12381] added tracing facility to the openshift-client bundle #55

Merged
merged 1 commit into from Feb 8, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 5 additions & 4 deletions plugins/org.jboss.tools.openshift.express.client/.classpath
@@ -1,11 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry exported="true" kind="lib" path="openshift-java-client-2.0.2-SNAPSHOT.jar" sourcepath="/openshift-java-client"/>
<classpathentry kind="src" path="src"/>
<classpathentry exported="true" kind="lib" path="log4j-1.2.17.jar" sourcepath="/home/adietish/Downloads/log4j-1.2.17.zip"/>
<classpathentry exported="true" kind="lib" path="openshift-java-client-2.0.2-SNAPSHOT.jar" sourcepath="/home/adietish/jboss-workspaces/openshift-java-client"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="lib" path="jboss-dmr-1.0.0.Final.jar"/>
<classpathentry kind="lib" path="log4j-1.2.16.jar"/>
<classpathentry kind="lib" path="slf4j-api-1.6.1.jar"/>
<classpathentry kind="lib" path="slf4j-log4j12-1.6.1.jar"/>
<classpathentry kind="lib" path="slf4j-api-1.6.1.jar" sourcepath="/home/adietish/.m2/repository/org/slf4j/slf4j-api/1.6.1/slf4j-api-1.6.1-sources.jar"/>
<classpathentry kind="lib" path="slf4j-log4j12-1.6.1.jar" sourcepath="/home/adietish/.m2/repository/org/slf4j/slf4j-log4j12/1.6.1/slf4j-log4j12-1.6.1-sources.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
2 changes: 2 additions & 0 deletions plugins/org.jboss.tools.openshift.express.client/.options
@@ -0,0 +1,2 @@
org.jboss.tools.openshift.express.client/debug=false
org.jboss.tools.openshift.express.client/debug/client=false
@@ -1,8 +1,11 @@
#Mon Nov 07 14:21:09 CET 2011
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.6
@@ -1,18 +1,20 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Client
Bundle-SymbolicName: org.jboss.tools.openshift.express.client
Bundle-SymbolicName: org.jboss.tools.openshift.express.client;singleton:=true
Bundle-Version: 2.4.0.qualifier
Bundle-Vendor: JBoss by Red Hat
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ClassPath: .,
openshift-java-client-2.0.2-SNAPSHOT.jar,
jboss-dmr-1.0.0.Final.jar,
log4j-1.2.16.jar,
log4j-1.2.17.jar,
slf4j-api-1.6.1.jar,
slf4j-log4j12-1.6.1.jar
Export-Package: com.openshift.client,
com.openshift.client.configuration,
com.openshift.client.utils
Require-Bundle: com.jcraft.jsch;bundle-version="0.1.44"
Require-Bundle: com.jcraft.jsch;bundle-version="0.1.44",
org.eclipse.core.runtime;bundle-version="3.8.0"
Import-Package: org.jboss.dmr
Bundle-ActivationPolicy: lazy
@@ -1,11 +1,10 @@
source.. = src/
src.includes = *
src.excludes = src
output.. = bin/
bin.includes = META-INF/,\
.,\
openshift-java-client-2.0.2-SNAPSHOT.jar,\
slf4j-api-1.6.1.jar,\
slf4j-log4j12-1.6.1.jar,\
log4j-1.2.16.jar,\
jboss-dmr-1.0.0.Final.jar
jboss-dmr-1.0.0.Final.jar,\
log4j-1.2.17.jar,\
plugin.xml
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,9 @@
log4j.rootLogger=TRACE, EclipseLogAppender

log4j.appender.EclipseLogAppender=org.jboss.tools.openshift.express.client.internal.log.EclipseLogAppender
log4j.appender.EclipseLogAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.EclipseLogAppender.layout.ConversionPattern=%m (%F:%L)

log4j.appender.ConsoleAppender=org.apache.log4j.ConsoleAppender
log4j.appender.ConsoleAppender.layout=org.apache.log4j.PatternLayout

16 changes: 16 additions & 0 deletions plugins/org.jboss.tools.openshift.express.client/plugin.xml
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
point="org.eclipse.ui.trace.traceComponents">
<component
id="org.jboss.tools.openshift.express.client"
label="OpenShift client">
<bundle
consumed="true"
name="org.jboss.tools.openshift.express.client">
</bundle>
</component>
</extension>

</plugin>
@@ -0,0 +1,128 @@
/*******************************************************************************
* Copyright (c) 2008 itemis AG (http://www.itemis.eu) and others.
* 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.jboss.tools.openshift.express.client.internal.log;

import org.apache.log4j.AppenderSkeleton;
import org.apache.log4j.Level;
import org.apache.log4j.Priority;
import org.apache.log4j.spi.LoggingEvent;
import org.eclipse.core.runtime.ILog;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;

/**
* @author Peter Friese - Initial contribution and API
* @author Sven Efftinge
* @author Knut Wannheden - Refactored handling when used in non OSGi
* environment
* @author Andre Dietisheim
*/
public class EclipseLogAppender extends AppenderSkeleton {

private static final String OPENSHIFT_CLIENT_BUNDLE = "org.jboss.tools.openshift.express.client";
private static final String OPENSHIFT_CLIENT_TRACE = "/client";

private ILog log;

private Trace trace;

public EclipseLogAppender() {
this.trace = new Trace(OPENSHIFT_CLIENT_BUNDLE);
}

@Override
protected void append(LoggingEvent event) {
if (Level.TRACE.equals(event.getLevel())) {
trace(event);
} else {
log(event);
}
}

private void trace(LoggingEvent event) {
if(trace.isDebugging()) {
trace.trace(OPENSHIFT_CLIENT_TRACE, String.valueOf(event.getMessage()));
}
}

private void log(LoggingEvent event) {
String logString = layout.format(event);
ILog myLog = getLog();
if (myLog != null) {
String loggerName = event.getLoggerName();
int severity = mapLevel(event.getLevel());
final Throwable throwable = event.getThrowableInformation() != null ? event
.getThrowableInformation().getThrowable() : null;
IStatus status = createStatus(severity, loggerName, logString,
throwable);
getLog().log(status);
} else {
// nothing to do (message should be logged to stdout by default
// appender)
}
}

private int mapLevel(Level level) {
switch (level.toInt()) {
case Priority.DEBUG_INT:
case Priority.INFO_INT:
return IStatus.INFO;

case Priority.WARN_INT:
return IStatus.WARNING;

case Priority.ERROR_INT:
case Priority.FATAL_INT:
return IStatus.ERROR;

default:
return IStatus.INFO;
}
}

private ILog getLog() {
if (log == null) {
log = Platform.getLog(Platform.getBundle(OPENSHIFT_CLIENT_BUNDLE));
}
return log;
}

private IStatus createStatus(int severity, String loggerName,
String message, Throwable throwable) {
return new Status(severity, OPENSHIFT_CLIENT_BUNDLE, message, throwable);
}

public void close() {
trace.close();
}

public boolean requiresLayout() {
return true;
}

// protected static boolean shouldTrace(String pluginId) {
// return shouldTrace0(pluginId + "/debug"); //$NON-NLS-1$
// }
//
// protected boolean shouldTrace0(String option) {
// if (option == null)
// return false;
// OpenShiftClientActivator.Activator activator = Activator.getDefault();
// if (activator == null)
// return false;
// DebugOptions debugOptions = activator.getDebugOptions();
// if (debugOptions == null)
// return false;
// String result = debugOptions.getOption(option);
// return (result == null) ? false : result.equalsIgnoreCase("true"); //$NON-NLS-1$
// }


}
@@ -0,0 +1,75 @@
package org.jboss.tools.openshift.express.client.internal.log;

import org.eclipse.osgi.service.debug.DebugOptions;
import org.eclipse.osgi.service.debug.DebugTrace;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.FrameworkUtil;
import org.osgi.util.tracker.ServiceTracker;

public class Trace {

public static final String GLOBAL_DEBUG_KEY = "/debug";

private static final boolean DEFAULT_DEBUG = false;

private String pluginId;
private DebugOptions options;
private ServiceTracker<DebugOptions, DebugOptions> tracker;
private DebugTrace trace;

public Trace(String pluginId) {
this.pluginId = pluginId;
}

public void close() {
if (tracker != null) {
tracker.close();
}
}

private DebugOptions createDebugOptions() {
Bundle bundle = FrameworkUtil.getBundle(getClass());
if (bundle == null) {
return null;
}
BundleContext context = bundle.getBundleContext();
if (context == null)
return null;
this.tracker =
new ServiceTracker<DebugOptions, DebugOptions>(context, DebugOptions.class.getName(), null);
tracker.open();
return tracker.getService();
}

public boolean isDebugging() {
Bundle bundle = FrameworkUtil.getBundle(getClass());
if (bundle == null) {
return DEFAULT_DEBUG;
}

if (getDebugOptions() == null) {
return DEFAULT_DEBUG;
}

return getDebugOptions().isDebugEnabled();
}

private DebugTrace getDebugTrace() {
if (trace == null) {
this.trace = getDebugOptions().newDebugTrace(pluginId);
}
return trace;
}

public void trace(String option, String message) {
getDebugTrace().trace(GLOBAL_DEBUG_KEY + option, message);
}

private DebugOptions getDebugOptions() {
if (options == null) {
this.options = createDebugOptions();
}
return this.options;
}
}