|
17 | 17 |
|
18 | 18 | package org.openapitools.codegen.cmd;
|
19 | 19 |
|
| 20 | +import ch.qos.logback.classic.LoggerContext; |
| 21 | +import ch.qos.logback.core.spi.FilterAttachable; |
20 | 22 | import io.airlift.airline.Command;
|
21 | 23 | import io.airlift.airline.Option;
|
22 | 24 | import org.openapitools.codegen.ClientOptInput;
|
|
32 | 34 |
|
33 | 35 | import java.util.ArrayList;
|
34 | 36 | import java.util.List;
|
| 37 | +import java.util.stream.Stream; |
35 | 38 |
|
36 | 39 | /**
|
37 | 40 | * User: lanwen Date: 24.03.15 Time: 20:22
|
@@ -199,8 +202,23 @@ public class Generate implements Runnable {
|
199 | 202 | description = "Skips the default behavior of validating an input specification.")
|
200 | 203 | private Boolean skipValidateSpec;
|
201 | 204 |
|
| 205 | + @Option(name = {"--log-to-stderr"}, |
| 206 | + title = "Log to STDERR", |
| 207 | + description = "write all log messages (not just errors) to STDOUT." |
| 208 | + + " Useful for piping the JSON output of debug options (e.g. `-DdebugOperations`) to an external parser directly while testing a generator.") |
| 209 | + private Boolean logToStderr; |
| 210 | + |
202 | 211 | @Override
|
203 | 212 | public void run() {
|
| 213 | + if (logToStderr != null) { |
| 214 | + LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); |
| 215 | + Stream.of(Logger.ROOT_LOGGER_NAME, "io.swagger", "org.openapitools") |
| 216 | + .map(lc::getLogger) |
| 217 | + .peek(logger -> logger.detachAppender("STDOUT")) |
| 218 | + .reduce((logger, next) -> logger.getName().equals(Logger.ROOT_LOGGER_NAME) ? logger : next) |
| 219 | + .map(root -> root.getAppender("STDERR")) |
| 220 | + .ifPresent(FilterAttachable::clearAllFilters); |
| 221 | + } |
204 | 222 |
|
205 | 223 | // attempt to read from config file
|
206 | 224 | CodegenConfigurator configurator = CodegenConfigurator.fromFile(configFile);
|
|
0 commit comments