Skip to content

Commit

Permalink
YARG-34 Log information from LibreOffice output using slf4j-api
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Subbotin committed Sep 5, 2017
1 parent 0860f8e commit bce6a82
Showing 1 changed file with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
* http:https://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.
*/
Expand Down Expand Up @@ -91,7 +91,7 @@ public OOServer(String oooExecFolder, List oooOptions, String host, int port, Pr
* 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
Expand All @@ -118,8 +118,8 @@ public void start() throws BootstrapException, IOException {
// start office process
oooProcess = Runtime.getRuntime().exec(oooCommand);

pipe(oooProcess.getInputStream(), System.out, "CO> ");
pipe(oooProcess.getErrorStream(), System.err, "CE> ");
pipe(oooProcess.getInputStream(), "OUT");
pipe(oooProcess.getErrorStream(), "ERR");
}

/**
Expand All @@ -128,17 +128,17 @@ public void start() throws BootstrapException, IOException {
* 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<Long> pids = processManager.findPid(host, port);
processManager.kill(oooProcess, pids);
oooProcess = null;
}
}

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));
Expand All @@ -148,10 +148,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();
Expand Down

0 comments on commit bce6a82

Please sign in to comment.