提交 4e6f107e 编写于 作者: S serge-rider

Debug logger redesign (dump all stdout and stderr in log)

上级 b126276f
......@@ -40,15 +40,17 @@ import org.jkiss.dbeaver.core.DBeaverUI;
import org.jkiss.dbeaver.core.application.rpc.DBeaverInstanceServer;
import org.jkiss.dbeaver.core.application.rpc.IInstanceController;
import org.jkiss.dbeaver.core.application.rpc.InstanceClient;
import org.jkiss.dbeaver.utils.GeneralUtils;
import org.jkiss.dbeaver.utils.SystemVariablesResolver;
import org.jkiss.utils.ArrayUtils;
import org.jkiss.utils.CommonUtils;
import org.jkiss.utils.IOUtils;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleEvent;
import org.osgi.framework.BundleListener;
import java.io.File;
import java.io.*;
import java.net.URL;
import java.rmi.RemoteException;
import java.util.ArrayList;
......@@ -69,6 +71,10 @@ public class DBeaverApplication implements IApplication {
private static DBeaverApplication instance;
private IInstanceController instanceServer;
private OutputStream debugWriter;
private PrintStream oldSystemOut;
private PrintStream oldSystemErr;
static {
// Explicitly set UTF-8 as default file encoding
// In some places Eclipse reads this property directly.
......@@ -169,6 +175,9 @@ public class DBeaverApplication implements IApplication {
// Init Core plugin and mark it as standalone version
DBeaverCore.setStandalone(true);
initDebugWriter();
log.debug(DBeaverCore.getProductTitle() + " is starting"); //$NON-NLS-1$
log.debug("Install path: '" + SystemVariablesResolver.getInstallPath() + "'"); //$NON-NLS-1$ //$NON-NLS-2$
log.debug("Instance path: '" + instanceLoc.getURL() + "'"); //$NON-NLS-1$ //$NON-NLS-2$
......@@ -267,10 +276,41 @@ public class DBeaverApplication implements IApplication {
workbench.close();
}
});
} catch (Throwable e) {
log.error(e);
} finally {
instance = null;
stopDebugWriter();
}
}
private void initDebugWriter() {
File logPath = GeneralUtils.getMetadataFolder();
File debugLogFile = new File(logPath, "dbeaver-debug.log"); //$NON-NLS-1$
if (debugLogFile.exists()) {
if (!debugLogFile.delete()) {
System.err.println("Can't delete debug log file"); //$NON-NLS-1$
}
}
try {
debugWriter = new FileOutputStream(debugLogFile);
oldSystemOut = System.out;
oldSystemErr = System.out;
System.setOut(new PrintStream(new ProxyPrintStream(debugWriter, oldSystemOut)));
System.setErr(new PrintStream(new ProxyPrintStream(debugWriter, oldSystemErr)));
} catch (IOException e) {
e.printStackTrace(System.err);
}
}
private void stopDebugWriter() {
if (oldSystemOut != null) System.setOut(oldSystemOut);
if (oldSystemErr != null) System.setErr(oldSystemErr);
if (debugWriter != null) {
IOUtils.close(debugWriter);
debugWriter = null;
}
}
......@@ -322,4 +362,20 @@ public class DBeaverApplication implements IApplication {
}
}
private class ProxyPrintStream extends OutputStream {
private final OutputStream debugWriter;
private final OutputStream stdOut;
public ProxyPrintStream(OutputStream debugWriter, OutputStream stdOut) {
this.debugWriter = debugWriter;
this.stdOut = stdOut;
}
@Override
public void write(int b) throws IOException {
debugWriter.write(b);
stdOut.write(b);
}
}
}
......@@ -109,9 +109,9 @@ public class Log
{
ModelActivator activator = ModelActivator.getInstance();
debugMessage(message, t, System.err);
if (activator != null) {
debugMessage(message, t, activator.getDebugWriter());
}
// if (activator != null) {
// debugMessage(message, t, activator.getDebugWriter());
// }
}
private static void debugMessage(Object message, Throwable t, PrintStream debugWriter) {
......
......@@ -19,11 +19,10 @@ package org.jkiss.dbeaver.bundle;
import org.eclipse.core.runtime.Plugin;
import org.jkiss.dbeaver.utils.GeneralUtils;
import org.jkiss.utils.IOUtils;
import org.osgi.framework.BundleContext;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintStream;
import java.io.*;
/**
* The activator class controls the plug-in life cycle
......@@ -33,7 +32,6 @@ public class ModelActivator extends Plugin
// The shared instance
private static ModelActivator instance;
private PrintStream debugWriter;
/**
* The constructor
......@@ -52,7 +50,6 @@ public class ModelActivator extends Plugin
throws Exception
{
super.start(context);
instance = this;
}
......@@ -60,15 +57,12 @@ public class ModelActivator extends Plugin
public void stop(BundleContext context)
throws Exception
{
if (debugWriter != null) {
debugWriter.close();
debugWriter = null;
}
instance = null;
super.stop(context);
}
/*
public synchronized PrintStream getDebugWriter()
{
if (debugWriter == null) {
......@@ -87,5 +81,6 @@ public class ModelActivator extends Plugin
}
return debugWriter;
}
*/
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册