Skip to content

Commit

Permalink
feat: Added janino to have conditions in logging config
Browse files Browse the repository at this point in the history
Closes #107
  • Loading branch information
devatherock committed Oct 28, 2021
1 parent eb9547a commit b8a6929
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 13 deletions.
8 changes: 4 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Changelog

## [Unreleased]
### Added
- [#107](https://github.com/devatherock/artifactory-badge/issues/107): `janino` to have conditions in logging config
- `dependencycheck` gradle plugin to detect vulnerable dependencies

### Changed
- chore(deps): update plugin io.micronaut.application to v2.0.5
- chore: Added changelog-updater for creating missed changelog entries
- chore(deps): update plugin com.diffplug.spotless to v5.15.1
- chore(deps): update plugin io.micronaut.application to v2.0.6
- chore(deps): update plugin com.diffplug.spotless to v5.15.2
- chore(deps): update dependency org.projectlombok:lombok to v1.18.22
- chore(deps): update plugin com.diffplug.spotless to v5.17.0
- chore(deps): update plugin io.micronaut.application to v2.0.7
Expand Down
19 changes: 15 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,16 @@ docker run --rm \
devatherock/artifactory-badge:latest
```

### Environment variables for configuration
### Configurable properties
#### application.yml

```yaml
logger:
levels:
io.micronaut.http.server.netty.NettyHttpServer: TRACE # Optional. To enable HTTP server access logs
```
#### Environment variables
| Name | Required | Default | Description |
|---------------------------------------|--------------|------------------|-----------------------------------------------------------------------------------|
Expand All @@ -31,6 +40,7 @@ docker run --rm \
| LOGGER_LEVELS_IO_GITHUB_DEVATHEROCK | false | INFO | [SLF4J](http://www.slf4j.org/api/org/apache/commons/logging/Log.html) log level, for custom code |
| MICRONAUT_ENVIRONMENTS | false | (None) | Setting the value to `local` will mock the calls to the artifactory. Only for testing purposes |
| MICRONAUT_SERVER_PORT | false | 8080 | Port in which the app listens on |
| MICRONAUT_CONFIG_FILES | true | (None) | Path to YAML config files. The YAML files can be used to specify complex, object and array properties |
| JAVA_OPTS | false | (None) | Additional JVM arguments to be passed to the container's java process |

### Endpoints
Expand Down Expand Up @@ -70,7 +80,8 @@ docker run --rm \
and set the environment variable `JAVA_OPTS` to `-Dlogback.configurationFile=/path/to/custom/logback.xml`

### JSON logs
Refer [logstash-logback-encoder](https://github.com/logstash/logstash-logback-encoder) documentation to customize the field names and formats in the log

To output logs as JSON, set the environment variable `JAVA_OPTS` to `-Dlogback.configurationFile=logback-json.xml`. Refer
[logstash-logback-encoder](https://github.com/logstash/logstash-logback-encoder) documentation to customize the field names and
formats in the log
- With the default logging config, if `MICRONAUT_ENVIRONMENTS` environment variable has the value `local`, logs will be in plain text(not JSON) format. Else they will be in JSON format
- To output logs as JSON all the time, set the environment variable `JAVA_OPTS` to `-Dlogback.configurationFile=logback-json.xml`
- To output logs as plain text(not JSON) all the time, set the environment variable `JAVA_OPTS` to `-Dlogback.configurationFile=logback-plain.xml`
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ plugins {
id 'org.sonarqube' version '3.3'
id 'com.github.kt3k.coveralls' version '2.12.0'
id 'com.diffplug.spotless' version '5.17.0'
id 'org.owasp.dependencycheck' version '6.4.1.1'
}

version "0.4.0"
Expand Down Expand Up @@ -48,8 +49,11 @@ dependencies {
implementation "io.micronaut.cache:micronaut-cache-caffeine"

implementation group: 'net.logstash.logback', name: 'logstash-logback-encoder', version: '6.6'
implementation group: 'org.codehaus.janino', name: 'janino', version: '3.1.6'
implementation group: 'io.netty', name: 'netty-all', version: '4.1.69.Final'

runtimeOnly "ch.qos.logback:logback-classic:1.2.6"

testAnnotationProcessor platform("io.micronaut:micronaut-bom:$micronautVersion")
testAnnotationProcessor "io.micronaut:micronaut-inject-java"
testImplementation "io.micronaut:micronaut-inject-groovy"
Expand Down
1 change: 0 additions & 1 deletion src/main/resources/logback-json.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@
<root level="INFO">
<appender-ref ref="STDOUT" />
</root>
<logger name="io.micronaut.http.server.netty.NettyHttpServer" level="TRACE" />
</configuration>
14 changes: 14 additions & 0 deletions src/main/resources/logback-plain.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<withJansi>true</withJansi>
<!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>

<root level="INFO">
<appender-ref ref="STDOUT" />
</root>
</configuration>
16 changes: 12 additions & 4 deletions src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,19 @@
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>

<appender name="JSON" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="net.logstash.logback.encoder.LogstashEncoder" />
</appender>

<root level="INFO">
<appender-ref ref="STDOUT" />
<if condition='property("MICRONAUT_ENVIRONMENTS").contains("local")'>
<then>
<appender-ref ref="STDOUT" />
</then>
<else>
<appender-ref ref="JSON" />
</else>
</if>
</root>
<logger name="io.micronaut.http.server.netty.NettyHttpServer" level="TRACE" />
<!--<logger name="io.micronaut.http.client" level="DEBUG" /> -->
<!--<logger name="io.micronaut.context.condition" level="TRACE" />-->
</configuration>

0 comments on commit b8a6929

Please sign in to comment.