Skip to content

Commit

Permalink
feat(logback): only use logback config in standalone server (#667)
Browse files Browse the repository at this point in the history
* fix deprecated pattern layout
* rename to logback-standalone.xml as to not override any default logback.xml files
* add env var to byo config file
fix #403 and #658
  • Loading branch information
tommytroen authored Apr 17, 2024
1 parent 4e3819d commit 68664e8
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 28 deletions.
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,14 @@ On Windows, it's easier to run the server in docker while specifying the host as

The standalone server supports the following configuration by `ENV` variables:

| Variable | Description |
|-------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `SERVER_HOSTNAME` | Lets the standalone server bind to a specific hostname, by default it binds to `0.0.0.0` |
| `SERVER_PORT` or `PORT` | The port that the standalone server will listen to, defaults to `8080`. The `PORT` environment variable may be used to [run the Docker image on Heroku](https://devcenter.heroku.com/articles/container-registry-and-runtime#pushing-an-existing-image) as per the documentation [here](https://devcenter.heroku.com/articles/setting-the-http-port-for-java-applications). |
| `JSON_CONFIG_PATH` | The absolute path to a json file containing configuration about the OAuth2 part of the server (`OAuth2Config`). More details on the format below. |
| `JSON_CONFIG` | The actual JSON content of `OAuth2Config`, this ENV var takes precedence over the `JSON_CONFIG_PATH` var. More details on the format below. |
| `LOG_LEVEL` | How verbose the root logging output is, defaults to `INFO` |
| Variable | Description |
|-------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `SERVER_HOSTNAME` | Lets the standalone server bind to a specific hostname, by default it binds to `0.0.0.0` |
| `SERVER_PORT` or `PORT` | The port that the standalone server will listen to, defaults to `8080`. The `PORT` environment variable may be used to [run the Docker image on Heroku](https://devcenter.heroku.com/articles/container-registry-and-runtime#pushing-an-existing-image) as per the documentation [here](https://devcenter.heroku.com/articles/setting-the-http-port-for-java-applications). |
| `JSON_CONFIG_PATH` | The absolute path to a json file containing configuration about the OAuth2 part of the server (`OAuth2Config`). More details on the format below. |
| `JSON_CONFIG` | The actual JSON content of `OAuth2Config`, this ENV var takes precedence over the `JSON_CONFIG_PATH` var. More details on the format below. |
| `LOG_LEVEL` | How verbose the root logging output is, defaults to `INFO` |
| `LOGBACK_CONFIG` | You can override the default logging config in [logback-standalone.xml](src/main/resources/logback-standalone.xml) with a path to your own logback xml file. |

##### JSON_CONFIG

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package no.nav.security.mock.oauth2

import ch.qos.logback.classic.ClassicConstants
import java.io.File
import java.io.FileNotFoundException
import java.net.InetAddress
import java.net.InetSocketAddress
import no.nav.security.mock.oauth2.StandaloneConfig.hostname
import no.nav.security.mock.oauth2.StandaloneConfig.oauth2Config
import no.nav.security.mock.oauth2.StandaloneConfig.port
import no.nav.security.mock.oauth2.http.NettyWrapper
import no.nav.security.mock.oauth2.http.OAuth2HttpResponse
import no.nav.security.mock.oauth2.http.route
import java.io.File
import java.io.FileNotFoundException
import java.net.InetAddress
import java.net.InetSocketAddress

object StandaloneConfig {
const val JSON_CONFIG = "JSON_CONFIG"
Expand Down Expand Up @@ -47,6 +48,7 @@ object StandaloneConfig {
}

fun main() {
System.setProperty(ClassicConstants.CONFIG_FILE_PROPERTY, "LOGBACK_CONFIG".fromEnv("logback-standalone.xml"))
MockOAuth2Server(
oauth2Config(),
route("/isalive") {
Expand Down
17 changes: 17 additions & 0 deletions src/main/resources/logback-standalone.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>
%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{70} - %msg%n
</pattern>
</encoder>
</appender>

<logger name="io.netty" level="info" />

<variable name="LOG_LEVEL" value="${LOG_LEVEL:-DEBUG}" />
<root level="${LOG_LEVEL}">
<appender-ref ref="STDOUT"/>
</root>
</configuration>
17 changes: 0 additions & 17 deletions src/main/resources/logback.xml

This file was deleted.

0 comments on commit 68664e8

Please sign in to comment.