Add log4j2-levels module: threshold rule, inheritance, additivity, custom levels, Actuator runtime changes and argument evaluation on Spring Boot 4.1.2 / Log4j2 2.25.5, with real transcripts
Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b5SFkZoaMCukJNvZCV
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
fe3fc689a6
commit
c9a2b766bb
Executable
+65
@@ -0,0 +1,65 @@
|
||||
#!/usr/bin/env bash
|
||||
# Transcripts 09 and 10: the real packaged jar under a real Tomcat, driven with curl.
|
||||
# 09 levels per logger, Actuator changes, the ROOT lookup
|
||||
# 10 logging.level.* properties and environment variables against log4j2-spring.xml
|
||||
set -uo pipefail
|
||||
source "$(dirname "$0")/lib.sh"
|
||||
P=com.ankurm.log4j2levels
|
||||
mkdir -p output
|
||||
[ -f "$JAR" ] || mvn -B -q package -DskipTests
|
||||
|
||||
OUT=output/09-live-run.txt
|
||||
{
|
||||
start_app 18091 /tmp/l4j-live.log || { echo "app did not start"; cat /tmp/l4j-live.log; exit 1; }
|
||||
SEEN=$(wc -l < /tmp/l4j-live.log)
|
||||
echo "# one request per logger name: JSON says which levels are enabled, the console shows what printed"
|
||||
for name in $P.service.Probe $P.billing.Probe $P.db.Probe $P.diag.Probe; do
|
||||
echo "\$ curl 'localhost:18091/demo/log?name=$name'"
|
||||
http GET 18091 "/demo/log?name=$name"; echo
|
||||
new_lines /tmp/l4j-live.log
|
||||
echo
|
||||
done
|
||||
echo "# raise billing to TRACE with Actuator, repeat the request"
|
||||
echo "\$ curl -X POST -H 'Content-Type: application/json' -d '{\"configuredLevel\":\"TRACE\"}' localhost:18091/actuator/loggers/$P.billing"
|
||||
http POST 18091 /actuator/loggers/$P.billing '{"configuredLevel":"TRACE"}'; echo
|
||||
http GET 18091 "/demo/log?name=$P.billing.Probe"; echo
|
||||
new_lines /tmp/l4j-live.log | grep -c 'TRACE' | sed 's/^/TRACE lines printed: /'
|
||||
echo
|
||||
echo "# the ROOT logger over real HTTP"
|
||||
http GET 18091 /actuator/loggers/ROOT; echo
|
||||
http GET 18091 /actuator/loggers/root; echo
|
||||
echo "# a level the endpoint does not know"
|
||||
http POST 18091 /actuator/loggers/$P.billing '{"configuredLevel":"DIAG"}'; echo
|
||||
stop_app
|
||||
} > "$OUT" 2>&1
|
||||
|
||||
OUT=output/10-property-overrides.txt
|
||||
{
|
||||
P2=$P.service
|
||||
echo "# log4j2-spring.xml says: $P2 = DEBUG, root = INFO"
|
||||
echo
|
||||
echo "# 1. --logging.level.$P2=WARN on the command line"
|
||||
start_app 18092 /tmp/l4j-p1.log --logging.level.$P2=WARN || { echo "did not start"; head -5 /tmp/l4j-p1.log; }
|
||||
http GET 18092 /actuator/loggers/$P2; echo; stop_app
|
||||
echo
|
||||
echo "# 2. the same override as an environment variable"
|
||||
LOGGING_LEVEL_COM_ANKURM_LOG4J2LEVELS_SERVICE=TRACE start_app 18093 /tmp/l4j-p2.log || { echo "did not start"; head -5 /tmp/l4j-p2.log; }
|
||||
http GET 18093 /actuator/loggers/$P2; echo; stop_app
|
||||
echo
|
||||
echo "# 3. --logging.level.root=ERROR, which the XML's root level should be competing with"
|
||||
start_app 18094 /tmp/l4j-p3.log --logging.level.root=ERROR || { echo "did not start"; head -5 /tmp/l4j-p3.log; }
|
||||
http GET 18094 /actuator/loggers/$P.billing.InvoiceService; echo; stop_app
|
||||
echo
|
||||
echo "# 4. a custom level through the property: --logging.level.$P2=DIAG"
|
||||
if start_app 18095 /tmp/l4j-p4.log --logging.level.$P2=DIAG; then
|
||||
echo "app started"; http GET 18095 /actuator/loggers/$P2; echo; stop_app
|
||||
else
|
||||
echo "app did not start; first lines of its output:"
|
||||
grep -vE '^\s+at |JAVA_TOOL|^$' /tmp/l4j-p4.log | head -16
|
||||
fi
|
||||
echo
|
||||
echo "# 5. a custom level in a separate logger written as log4j2 itself reads it (see diag in the XML)"
|
||||
start_app 18096 /tmp/l4j-p5.log || echo "did not start"
|
||||
http GET 18096 /actuator/loggers/$P.diag; echo; stop_app
|
||||
} > "$OUT" 2>&1
|
||||
echo "wrote output/09-live-run.txt and output/10-property-overrides.txt"
|
||||
Reference in New Issue
Block a user