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
(cherry picked from commit bce6a82)
  • Loading branch information
Andrey Subbotin authored and IlyaChekashkin committed Feb 6, 2020
1 parent 733aee2 commit bdee7e7
Showing 1 changed file with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,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 @@ -99,7 +99,7 @@ public OOServer(String oooExecFolder, List<String> 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
Expand Down Expand Up @@ -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) {
Expand All @@ -143,18 +143,18 @@ 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<Long> pids = processManager.findPid(host, port);
processManager.kill(oooProcess, pids);
oooProcess = null;
deleteProfileDir();
}
}

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 @@ -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();
Expand Down

0 comments on commit bdee7e7

Please sign in to comment.