Skip to content

Commit

Permalink
[cli] Write to stdout/stderr, allow redirection (#207)
Browse files Browse the repository at this point in the history
* [cli] Write to stdout/stderr, allow redirection

Previously, slf4j-simple from generator core was being used. This writes
to only a single stream (STDERR) and is confusing from a CLI tooling
perspective.

This consumes logback in CLI, and excludes core's slf4j-simple
dependency. This allows us to define multiple appenders, one for STDOUT
and one for STDERR.

WARN messages and lower are written to STDOUT. ERROR is written to
STDERR.

* [cli] Limit logs to match prev implementation

* Remove slf4j-simple from core project, to avoid conflicts with consumer logger implementations
  • Loading branch information
jimschubert authored and wing328 committed Jun 7, 2018
1 parent 0fb1ffa commit f4c66d9
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 29 deletions.
13 changes: 9 additions & 4 deletions modules/openapi-generator-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
<directory>src/main/resources</directory>
<filtering>true</filtering>
<excludes>
<exclude>logback.xml</exclude>
</excludes>
</resource>
</resources>
Expand Down Expand Up @@ -78,6 +77,12 @@
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator</artifactId>
<version>${project.version}</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
</exclusion>
</exclusions>
</dependency>
<!--https://github.com/airlift/airline-->
<dependency>
Expand All @@ -91,9 +96,9 @@
<version>2.3.3</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>${slf4j-version}</version>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.0.13</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
Expand Down
32 changes: 27 additions & 5 deletions modules/openapi-generator-cli/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</Pattern>
</layout>
<target>System.out</target>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>[%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>ERROR</level>
<onMatch>DENY</onMatch>
<onMismatch>NEUTRAL</onMismatch>
</filter>
</appender>
<logger name="io.swagger" level="debug"/>
<root level="error">
<appender name="STDERR" class="ch.qos.logback.core.ConsoleAppender">
<target>System.err</target>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>[%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>ERROR</level>
</filter>
</appender>
<logger name="io.swagger" level="warn">
<appender-ref ref="STDOUT"/>
<appender-ref ref="STDERR"/>
</logger>
<logger name="org.openapitools" level="info">
<appender-ref ref="STDOUT"/>
<appender-ref ref="STDERR"/>
</logger>
<root level="error">
<appender-ref ref="STDERR"/>
</root>
</configuration>
5 changes: 0 additions & 5 deletions modules/openapi-generator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,6 @@
<artifactId>slf4j-api</artifactId>
<version>${slf4j-version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>${slf4j-version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
Expand Down
12 changes: 0 additions & 12 deletions modules/openapi-generator/src/main/resources/logback.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
import org.openapitools.codegen.CodegenProperty;
import org.openapitools.codegen.DefaultCodegen;
import org.openapitools.codegen.languages.PhpClientCodegen;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
Expand All @@ -46,7 +44,6 @@

@SuppressWarnings("static-method")
public class PhpModelTest {
private static final Logger LOGGER = LoggerFactory.getLogger(PhpModelTest.class);

@Test(description = "convert a simple php model")
public void simpleModelTest() {
Expand Down

0 comments on commit f4c66d9

Please sign in to comment.