5

What is the correct/easiest way to redirect output (out/err) from .execute() or .parseArgs() to a logger (org.slf4j.Logger)?

(Production processes are often executed by a scheduler with output to application-specific log files. And stdout/err, if not redirected, gets dumped in the scheduler/server log - which is not appropriate. Hence this question.)

I have something like this:

Logger logger = LoggerFactory.getLogger(MyApp.class);
    // ...
    new CommandLine(new MyApp())
      .setOut(new LoggerWriter(logger, Level.INFO)
      .setErr(new LoggerWriter(logger, Level.ERROR)
      .execute(args);
    // ...

where the LoggerWriter class is inspired from here.

Kap4Lin
  • 109
  • 5

0 Answers0