Skip to content

Commit

Permalink
Improve logging
Browse files Browse the repository at this point in the history
  • Loading branch information
jkroepke committed May 23, 2021
1 parent 49db38e commit 2d3f32b
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 39 deletions.
4 changes: 1 addition & 3 deletions .edge-build.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
FROM maven:3-openjdk-11-slim

ENV KEYCLOAK_VERSION=""
ENV MAVEN_CLI_OPTS="-B -ntp"
ENV IMPORT_PATH=/config
ENV KEYCLOAK_VERSION="" MAVEN_CLI_OPTS="-B -ntp" IMPORT_PATH=file:/config

USER 1001

Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added
- JSON logging

## [3.4.0] - 2021-05-12

### Added
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM adoptopenjdk/openjdk11:alpine-jre

ENV JAVA_OPTS="" KEYCLOAK_SSL_VERIFY=true IMPORT_PATH=/config
ENV JAVA_OPTS="" KEYCLOAK_SSL_VERIFY=true IMPORT_PATH=file:/config
ENTRYPOINT exec java $JAVA_OPTS -jar /app/keycloak-config-cli.jar $0 $@
COPY ./target/keycloak-config-cli.jar /app/

Expand Down
43 changes: 33 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,20 @@ See [Apache Common StringSubstitutor documentation](https://commons.apache.org/p

If the import contains some keycloak builtin variables like `${role_uma_authorization}`, they need to be escaped by `$${role_uma_authorization}`.

# Logging

## JSON logging support

keycloak-config-cli supports logging in JSON format. To enable, set `SPRING_PROFILES_ACTIVE=json-log`.

## Log level

| CLI Option | ENV Variable | Description | Default |
| ---------------------------------- | ------------------------------- | ---------------------------------------------------------------- | ---------------------------- |
| --loging.level.root | LOGGING_LEVEL_ROOT | define the root log level | `info` |
| --loging.level.keycloak-config-cli | LOGGING_LEVEL_KEYCLOAKCONFIGCLI | log level of keycloak-config-cli components | value of `loging.level.root` |
| --loging.level.http | LOGGING_LEVEL_HTTP | log level http requests between keycloak-config-cli and Keycloak | value of `loging.level.root` |

# Supported features

See: [docs/FEATURES.md](./docs/FEATURES.md)
Expand Down Expand Up @@ -120,15 +134,14 @@ A docker images is available at [DockerHub](https://hub.docker.com/r/adorsys/key

Available docker tags

| Tag | Description |
|-----|-------------|
| `latest` | latest available release of keycloak-config-cli which is built against the latest supported Keycloak release. |
| `latest-x.y.z` | latest available release of keycloak-config-cli which is built against the Keycloak version `x.y.z`. |
| `edge` | latest commit on the main branch and which is built against the latest supported Keycloak release. |
| `a.b.c` | keycloak-config-cli version `a.b.c` which is built against the latest supported Keycloak release. |
| `a.b.c-x.y.z` | keycloak-config-cli version `a.b.c` which is built against the Keycloak version `x.y.z`. |
| `maven` | See below |

| Tag | Description |
| -------------- | ------------------------------------------------------------------------------------------------------------- |
| `latest` | latest available release of keycloak-config-cli which is built against the latest supported Keycloak release. |
| `latest-x.y.z` | latest available release of keycloak-config-cli which is built against the Keycloak version `x.y.z`. |
| `edge` | latest commit on the main branch and which is built against the latest supported Keycloak release. |
| `a.b.c` | keycloak-config-cli version `a.b.c` which is built against the latest supported Keycloak release. |
| `a.b.c-x.y.z` | keycloak-config-cli version `a.b.c` which is built against the Keycloak version `x.y.z`. |
| `maven` | See below |

Additionally, the tag `maven` contains the source code and compile keycloak-config-cli at runtime. This has the advantage to keycloak-config-cli with
Keycloak versions, that not official supported., e.g.:
Expand Down Expand Up @@ -163,7 +176,9 @@ add it as dependency to your chart deployment.

Checkout helm docs about [chart dependencies](https://helm.sh/docs/topics/charts/#chart-dependencies)!

# CLI option / Environment Variables
# Configuration

## CLI option / Environment Variables

| CLI Option | ENV Variable | Description | Default | Docs |
| ----------------------------------------------------- | -------------------------------------------------- | --------------------------------------------------------------------------------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------- |
Expand Down Expand Up @@ -198,6 +213,14 @@ For docker `-e` you have to remove hyphens and replace dots with underscores.
Take a look at [spring relax binding](https://github.com/spring-projects/spring-boot/wiki/Relaxed-Binding-2.0) if you need
alternative spellings.

## Spring boot options

| CLI Option | ENV Variable | Description | Default | Docs |
| ------------------------ | ---------------------- | --------------------------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| --spring.profiles.active | SPRING_PROFILES_ACTIVE | enable spring profiles. comma separated | `-` | [Set the Active Spring Profiles](https://docs.spring.io/spring-boot/docs/current/reference/html/howto.html#howto.properties-and-configuration.set-active-spring-profiles) |
| --loging.level.root | LOGGING_LEVEL_ROOT | define the root log level | `info` | [Logging](https://docs.spring.io/spring-boot/docs/current/reference/html/howto.html#howto.logging) |
| --debug | DEBUG | enables debug mode of spring boot | `false` | |

## Configure properties values through files

_Available since keycloak-config-cli 2.6.3._
Expand Down
37 changes: 21 additions & 16 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,7 @@
<developers>
<developer>
<name>Jan-Otto Kröpke</name>
<email>joe@adorsys.de</email>
<organization>adorsys GmbH &amp; Co. KG</organization>
<organizationUrl>https://www.adorsys.com/</organizationUrl>
</developer>
<developer>
<name>Boris Skert</name>
<email>bsk@adorsys.de</email>
<organization>adorsys GmbH &amp; Co. KG</organization>
<organizationUrl>https://www.adorsys.com/</organizationUrl>
</developer>
<developer>
<name>Francis Pouatcha</name>
<email>fpo@adorsys.de</email>
<email>jan-otto.kroepke@adorsys.com</email>
<organization>adorsys GmbH &amp; Co. KG</organization>
<organizationUrl>https://www.adorsys.com/</organizationUrl>
</developer>
Expand Down Expand Up @@ -76,6 +64,7 @@
<junit5-system-exit.version>1.1.1</junit5-system-exit.version>
<keepachangelog.version>2.1.1</keepachangelog.version>
<license-plugin.version>2.0.0</license-plugin.version>
<logstash-logback-encoder.version>6.6</logstash-logback-encoder.version>
<maven-failsafe-plugin.version>3.0.0-M5</maven-failsafe-plugin.version>
<maven-release-plugin.version>3.0.0-M4</maven-release-plugin.version>
<maven-replacer.version>1.5.3</maven-replacer.version>
Expand All @@ -102,7 +91,6 @@
<version>2.5.0</version>
</parent>

<!-- Intellij friendly POM -->
<dependencyManagement>
<dependencies>
<dependency>
Expand All @@ -128,6 +116,18 @@
<scope>import</scope>
<type>pom</type>
</dependency>

<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${commons-io.version}</version>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons-lang3.version}</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down Expand Up @@ -177,13 +177,11 @@
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${commons-io.version}</version>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons-lang3.version}</version>
</dependency>

<dependency>
Expand All @@ -208,6 +206,13 @@
<artifactId>jackson-dataformat-yaml</artifactId>
</dependency>

<!-- JSON logging -->
<dependency>
<groupId>net.logstash.logback</groupId>
<artifactId>logstash-logback-encoder</artifactId>
<version>${logstash-logback-encoder.version}</version>
</dependency>

<!-- TEST -->
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,6 @@ public void doImport(RealmImport realmImport) {
} else {
createRealm(realmImport);
}

keycloakProvider.close();
}

private void updateRealmIfNecessary(RealmImport realmImport) {
Expand Down
4 changes: 1 addition & 3 deletions src/main/resources/application-debug.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
logging.level.de.adorsys.keycloak.config.service=debug
logging.level.de.adorsys.keycloak.config.KeycloakConfigRunner=debug
logging.level.de.adorsys.keycloak.config.provider.KeycloakProvider=debug
logging.level.keycloak-config-cli=debug
2 changes: 1 addition & 1 deletion src/main/resources/application-http-debug.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
logging.level.org.apache.http.wire=debug
logging.level.http=debug
5 changes: 5 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ spring.main.web-application-type=NONE
spring.main.log-startup-info=true
spring.main.banner-mode=off
spring.main.lazy-initialization=true
spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.availability.ApplicationAvailabilityAutoConfiguration

keycloak.login-realm=master
keycloak.user=admin
Expand Down Expand Up @@ -39,3 +40,7 @@ import.managed.identity-provider=full
import.managed.identity-provider-mapper=full
import.managed.role=full
import.managed.client=full

logging.group.http=org.apache.http.wire
logging.group.keycloak-config-cli=de.adorsys.keycloak.config.service,de.adorsys.keycloak.config.KeycloakConfigRunner,de.adorsys.keycloak.config.provider.KeycloakProvider
logging.group.kcc=de.adorsys.keycloak.config.service,de.adorsys.keycloak.config.KeycloakConfigRunner,de.adorsys.keycloak.config.provider.KeycloakProvider
18 changes: 18 additions & 0 deletions src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>

<springProfile name="! json-log">
<include resource="org/springframework/boot/logging/logback/console-appender.xml" />
</springProfile>

<springProfile name="json-log">
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="net.logstash.logback.encoder.LogstashEncoder"/>
</appender>
</springProfile>

<root level="INFO">
<appender-ref ref="CONSOLE" />
</root>
</configuration>
3 changes: 0 additions & 3 deletions src/test/resources/application-IT.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,3 @@ keycloak.password=admin123
keycloak.url=http://localhost:8080/auth/
import.path=default
import.state=true
logging.level.de.adorsys.keycloak.config.service=debug
logging.level.de.adorsys.keycloak.config.KeycloakConfigRunner=debug
logging.level.de.adorsys.keycloak.config.provider.KeycloakProvider=debug

0 comments on commit 2d3f32b

Please sign in to comment.