Commits

Anonymous committed 6a927bb Merge

Merge log with lispdev.

Comments (0)

Files changed (9)

+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<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="src" path="src"/>
+	<classpathentry kind="output" path="bin"/>
+</classpath>
+# Turn on debug tracing for lispdev plugins
+org.lispdev.log/trace/debug=false
+org.lispdev.log/trace/console=false
+org.lispdev.log/trace/swank=false
+org.lispdev.log/trace/swank-events=false
+org.lispdev.log/trace/scanner=false
+
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>org.lispdev.log</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.pde.ManifestBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.pde.SchemaBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.pde.PluginNature</nature>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+	</natures>
+</projectDescription>

.settings/org.eclipse.jdt.core.prefs

+#Sat Jul 17 23:38:22 CDT 2010
+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.compliance=1.6
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6

META-INF/MANIFEST.MF

+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Log
+Bundle-SymbolicName: org.lispdev.log
+Bundle-Version: 1.0.0.qualifier
+Bundle-Activator: org.lispdev.log.LispLogPlugin
+Require-Bundle: org.eclipse.core.runtime
+Bundle-ActivationPolicy: lazy
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Export-Package: org.lispdev.log
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+               .

src/org/lispdev/log/LispLogPlugin.java

+package org.lispdev.log;
+
+import java.io.PrintStream;
+
+import org.eclipse.core.runtime.Plugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class LispLogPlugin extends Plugin
+{
+
+  // The plug-in ID
+  public static final String ID = "org.lispdev.log";
+
+  // The shared instance
+  private static LispLogPlugin plugin;
+
+  /**
+   * The constructor
+   */
+  public LispLogPlugin()
+  {}
+
+  /*
+   * (non-Javadoc)
+   *
+   * @see
+   * org.eclipse.core.runtime.Plugins#start(org.osgi.framework.BundleContext)
+   */
+  @Override
+  public void start(BundleContext context) throws Exception
+  {
+    super.start(context);
+    plugin = this;
+  }
+
+  /*
+   * (non-Javadoc)
+   *
+   * @see org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext)
+   */
+  @Override
+  public void stop(BundleContext context) throws Exception
+  {
+    plugin = null;
+    super.stop(context);
+  }
+
+  /**
+   * Returns the shared instance
+   *
+   * @return the shared instance
+   */
+  public static LispLogPlugin get()
+  {
+    return plugin;
+  }
+
+  // === some code for tracing
+  private PrintStream traceStream;
+
+  /**
+   * Sets stream for tracing done by Trace enums.
+   */
+  public void setTraceStream(PrintStream pr)
+  {
+    traceStream = pr;
+  }
+
+  /**
+   * Returns stream which receives tracing from Trace enums.
+   */
+  public PrintStream getTraceStream()
+  {
+    if( traceStream == null )
+    {
+      return System.out;
+    }
+    else
+    {
+      return traceStream;
+    }
+  }
+
+
+}

src/org/lispdev/log/Log.java

+package org.lispdev.log;
+
+import java.lang.management.ManagementFactory;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+
+/**
+ * <h1>Logging Facility</h1>
+ * <h2>How to log in code</h2>
+ * To log a message use one of the four functions: {@link EtLog#logInfo},
+ * {@link EtLog#logWarning}, {@link EtLog#logError},
+ * or {@link EtLog#logException}.
+ */
+public class Log
+{
+  public static void appendCallInformation(StringBuilder sb, int lvl, String tag)
+  {
+    final StackTraceElement ste = Thread.currentThread().getStackTrace()[lvl];
+    sb.append('(');
+    sb.append(ste.getFileName());
+    sb.append(':');
+    sb.append(ste.getLineNumber());
+    sb.append(')');
+    sb.append('<');
+    sb.append(tag);
+    sb.append(':');
+    sb.append(ste.getMethodName());
+    sb.append(':');
+    sb.append(ManagementFactory.getRuntimeMXBean().getUptime());
+    sb.append('>');
+  }
+
+  /**
+   * Throws exception with custom message.
+   * @param message Message that is assigned to the exception
+   * @param e a low-level exception or <tt>null</tt> if not applicable
+   * @throws CoreException
+   *
+   * <p>
+   * This is a convenience function to throw an exception with custom
+   * message.
+   */
+  public static void abort(String message, Throwable e) throws CoreException
+  {
+    throw new CoreException(new Status(IStatus.ERROR, LispLogPlugin.ID,
+        0, message, e));
+  }
+
+  /**
+   * @param message
+   * @param severity
+   *          Integer constant from {@org.eclipse.core.runtime.IStatus}
+   */
+  private static void log(String message, int severity, Throwable e)
+  {
+    StringBuilder sb = new StringBuilder();
+    appendCallInformation(sb, 4, "");
+    sb.append(" ");
+    sb.append(message);
+    LispLogPlugin.get().getLog().log(
+        new Status(severity, LispLogPlugin.ID, 0, sb.toString(), e));
+    Trace.DEBUG.trace("Logged lvl "+severity+": "+sb.toString());
+  }
+
+
+  public static void logInfo(String message)
+  {
+    log(message, IStatus.INFO, null);
+  }
+
+  public static void logWarning(String message)
+  {
+    log(message, IStatus.WARNING, null);
+  }
+
+  public static void logError(String message)
+  {
+    log(message, IStatus.ERROR, null);
+  }
+
+  public static void logException(String message, Throwable e)
+  {
+    log(message, IStatus.ERROR, e);
+  }
+
+  public static void logException(Throwable e)
+  {
+    log((e != null ? e.getMessage() : "Exception"), IStatus.ERROR, e);
+  }
+
+}

src/org/lispdev/log/Trace.java

+package org.lispdev.log;
+
+import java.io.PrintStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.Platform;
+
+/**
+ * <h1>Tracing Facility</h1>
+ *
+ * <h2>Tracing in code</h2>
+ * Before sending a message to current trace stream check if tracing is enabled
+ * using {@link Trace#enabled}. Then send a message to the trace stream using
+ * {@link Trace#trace}.
+ * Example:
+ * <br> <code>if(Trace.DEBUG.enabled) Trace.DEBUG.trace("message");</code>
+ * <p> If the tracing is not enabled on application start, its penalty
+ * is minimal, so it is encouraged to use tracing heavily.
+ * <p> By default the tracing will be sent to <code>stdout</code>, but it
+ * is possible to change it by calling {@link LispLogPlugin#setTraceStream}.
+ *
+ * <h2>Enable tracing during development from Eclipse</h2>
+ * Open "Run configurations..." dialog, select launch configuration for
+ * and select "Tracing" tab. Switch on "Enable tracing" box,
+ * and select plugins that you want to trace and which tracing tags to enable.
+ *
+ * <h2>Enable tracing in stand-alone Eclipse running the plugin</h2>
+ * Start Eclipse from command line with the <code>-debug .options</code>
+ * arguments: <code>eclipse.exe -debug .options</code>. Where
+ * <code>.options</code> is a file in eclipse root
+ * folder containing tracing options. For example:<br>
+ * <code>org.lispdev.log/trace/debug=true<br>org.eclipse.help/debug=true</code>
+ *
+ * <h2>Adding new tracing tags</h2>
+ * To add new tracing tag:
+ * <ul>
+ * <li>add new enum value to {@link Trace} with
+ * corresponding tag name</li>
+ * <li>open <code>.options</code> file in root of <code>org.lispdev.log</code>
+ * plugin and add a line corresponding to the tag to the options. Eclipse needs
+ * restart for the option to be visible in "Tracing" tab of the
+ * launch configuration.
+ */
+public enum Trace
+{
+  /**
+   * General debug trace
+   */
+  DEBUG("debug"),
+  /**
+   * Trace for org.lispdev.console
+   */
+  CONSOLE("console"),
+  /**
+   * Trace for org.lispdev.swank
+   */
+  SWANK("swank"),
+  /**
+   * Trace for org.lispdev.swank holding swank events
+   */
+  SWANK_EVENTS("swank-events"),
+  SCANNER("scanner")
+  ;
+
+  public boolean enabled;
+  private final String tag;
+  private boolean saveLog;
+  private final List<String> log = new ArrayList<String>();
+
+  private Trace(String tag)
+  {
+    final String val =
+      Platform.getDebugOption(LispLogPlugin.ID + "/trace/" + tag);
+    enabled = (val != null && val.equalsIgnoreCase("true"));
+    this.tag = tag;
+  }
+
+  private static final String indent = "  ";
+
+  public void trace(String msg)
+  {
+    if( !enabled ) return;
+    StringBuilder sb = new StringBuilder();
+    Log.appendCallInformation(sb, 3, tag);
+    sb.append("\n");
+    if( msg != null )
+    {
+      String[] lines = msg.split("\n");
+      for( String s : lines )
+      {
+        sb.append(indent);
+        sb.append(s);
+        sb.append("\n");
+      }
+    }
+    else
+    {
+      sb.append("\n");
+    }
+    PrintStream out = LispLogPlugin.get().getTraceStream();
+    if( out == null )
+    {
+      out = System.out;
+    }
+    final String res = sb.toString();
+    out.print(res);
+    if( saveLog )
+    {
+      log.add(res);
+    }
+  }
+
+  public void setSaveLog(boolean x)
+  {
+    if( x && x != saveLog )
+    {
+      saveLog = true;
+      log.clear();
+    }
+  }
+
+  public List<String> getLog()
+  {
+    return log;
+  }
+}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.