Worker API and logging

(Kyle Moore) #1

Hi everyone.

I’m very excited about the new Worker API, and I am converting a long-running task to operate in a separate process (IsolationMode.PROCESS). However, I have noticed that all stdout of the action executed in the worker is echoed to the terminal, with no apparent API to control it. Is there a way to configure the log level?

Prior to the Worker API being released, I used a JavaExec task to accomplish something similar. In that case, I could wait for the exitcode of the JavaExec, then decide what I want to do with the stdout based on that. Here’s a simple example:

ByteArrayOutputStream stdout = new ByteArrayOutputStream();

ExecResult result = _project.javaexec(javaExecSpec -> {

int exitCode = result.getExitValue();

if(exitCode != 0 ) {
  LOGGER.quiet(stdout.toString()); //always log if there was a problem
} else {; //only log if info-level logging or higher was requested

I hope this makes sense.

Thanks in advance,