https://github.com/binkley/spring-boot-logging
Various Spring Boot logging niceties
https://github.com/binkley/spring-boot-logging
Last synced: 10 months ago
JSON representation
Various Spring Boot logging niceties
- Host: GitHub
- URL: https://github.com/binkley/spring-boot-logging
- Owner: binkley
- License: unlicense
- Created: 2019-09-18T21:45:16.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-08-02T12:35:44.000Z (over 1 year ago)
- Last Synced: 2025-03-20T10:56:14.302Z (10 months ago)
- Language: Java
- Size: 491 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Spring Boot logging
Various Spring Boot logging niceties
## Run the from command line
First, as a "local" program for developers:
1. Run `./mvnw` or `./gradlew`.
2. Run `java -jar build/libs/spring-boot-logging-0.0.1-SNAPSHOT.jar --help`.
Second, as a "production" project with structured logging (JSON; eg, for ELK):
1. Run `./mvnw` or `./gradlew`.
2. Run `java -jar build/libs/spring-boot-logging-0.0.1-SNAPSHOT.jar --json-logging`.
3. For easier reading, pipe the previous step through `| jq -cC . | less`
(single line per JSON) or `| jq -C . | less -R` (pretty-printed JSON).
## Features
General:
* Debug logging as it initializes with `-Dlogging.debug=true`
* Early control of logging during program initialization
* UTC timestamps
* Controller and Feign logging with Logbook
* Sleuth tracing through controllers and Feign, including responses
* Problem RFC responses and logging
- Constraint violations respond with 422 status (no examples)
- Feign exceptions respond with 502 status (one example)
* Distinct logging from alerting
* Suppress request body logging, and only show response bodies on error
* Top-level custom JSON properties for request/response logging
* Counting SQL queries for performance tests
* Distinguish 502 (server issue) from 503 (remote issue)
* [Prometheus queries](#prometheus-queries)
Local development:
* Full-color Spring Boot logging
* Human-friendly HTTP logging
* Maven and Gradle
* Docker Compose for _local_ testing of Prometheus/Grafana and ELK
Production use:
* JSON logging suitable for ELK with `--json-logging`
* Embedded JSON payloads (not quoted-string JSON)
* Custom JSON properties (ie, "environment")
* Micrometer timings on Feign clients and Spring Data repositories
## Key files
* [`AssertionsForTracingLogs`](src/test/java/x/loggy/AssertionsForTracingLogs.java)
* [`SqlQueries`](src/main/java/x/loggy/data/SqlQueries.java)
* [`TraceRequestInterceptor`](src/main/java/x/loggy/TraceRequestInterceptor.java)
* [`TraceResponseFilter`](src/main/java/x/loggy/TraceResponseFilter.java)
* [`application.yml`](src/main/resources/application.yml)
* [`bootstrap.yml`](src/main/resources/bootstrap.yml)
* [configuration classes](src/main/java/x/loggy/configuration/)
* [`logback-spring.xml`](src/main/resources/logback-spring.xml)
## Prometheus queries
```sh
$ ./mvnw package
$ ./docker-compose build
$ ./docker-compose up
$ open http://localhost:9090
```
## Drawbacks
As things stand now, the code couples too tightly to Spring Boot 2.1.x.
Updating to 2.2.x breaks things.
## Notes
* [ELK on Docker Compose](https://github.com/deviantony/docker-elk)