From bdee7e7819f0b0ef46e872c0607bc5820f68a9b2 Mon Sep 17 00:00:00 2001 From: Andrey Subbotin Date: Tue, 5 Sep 2017 17:27:28 +0400 Subject: [PATCH] YARG-34 Log information from LibreOffice output using slf4j-api (cherry picked from commit bce6a82bfb0f9f964b0ea45d323563e203babe92) --- .../impl/doc/connector/OOServer.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/core/modules/core/src/com/haulmont/yarg/formatters/impl/doc/connector/OOServer.java b/core/modules/core/src/com/haulmont/yarg/formatters/impl/doc/connector/OOServer.java index 01a9d281..55a952fe 100644 --- a/core/modules/core/src/com/haulmont/yarg/formatters/impl/doc/connector/OOServer.java +++ b/core/modules/core/src/com/haulmont/yarg/formatters/impl/doc/connector/OOServer.java @@ -42,7 +42,7 @@ * http://udk.openoffice.org/source/browse/udk/javaunohelper/com/sun/star/comp/helper/Bootstrap.java?view=markup */ public class OOServer { - protected static final Logger log = LoggerFactory.getLogger(JavaProcessManager.class); + protected static final Logger log = LoggerFactory.getLogger(OOServer.class); /** * The OOo server process. */ @@ -99,7 +99,7 @@ public OOServer(String oooExecFolder, List oooOptions, String host, int * the pipe name "oooPipe" the accept option looks like this: * - accept option : -accept=pipe,name=oooPipe;urp; */ - public void start() throws BootstrapException, IOException { + public synchronized void start() throws BootstrapException, IOException { // find office executable relative to this class's class loader String sOffice = System.getProperty("os.name").startsWith("Windows") ? "soffice.exe" : "soffice"; //accept option !Note! we are using old version notation (- instead of --) to support old version of office @@ -127,8 +127,8 @@ public void start() throws BootstrapException, IOException { // start office process oooProcess = Runtime.getRuntime().exec(argumentsList.toArray(new String[0])); - pipe(oooProcess.getInputStream(), System.out, "CO> "); - pipe(oooProcess.getErrorStream(), System.err, "CE> "); + pipe(oooProcess.getInputStream(), "OUT"); + pipe(oooProcess.getErrorStream(), "ERR"); } public String toUrl(File file) { @@ -143,9 +143,9 @@ public String toUrl(File file) { * nothing. * If there has been a previous start, kill destroys the process. */ - public void kill() { + public synchronized void kill() { if (oooProcess != null) { - log.info("OOServer is killing office instance with port " + port); + log.info("OOServer is killing office instance with port {}", port); List pids = processManager.findPid(host, port); processManager.kill(oooProcess, pids); oooProcess = null; @@ -153,8 +153,8 @@ public void kill() { } } - private static void pipe(final InputStream in, final PrintStream out, final String prefix) { - new Thread("Pipe: " + prefix) { + protected void pipe(final InputStream in, final String prefix) { + new Thread(String.format("OOServer: %s", prefix)) { @Override public void run() { BufferedReader r = new BufferedReader(new InputStreamReader(in)); @@ -164,10 +164,10 @@ public void run() { if (s == null) { break; } - out.println(prefix + s); + log.debug("{}: {}", prefix, s); } } catch (IOException e) { - e.printStackTrace(System.err); + log.debug("OOServer error:", e); } } }.start();