Skip to content

Commit 9f5d1f5

Browse files
authored
fix startup error for missing config/ ; fix JSON logging format (#152)
1 parent 72f6ad7 commit 9f5d1f5

File tree

6 files changed

+24
-13
lines changed

6 files changed

+24
-13
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ COPY "startup/${LABKEY_DISTRIBUTION}.properties" \
213213
startup/49_distribution.properties
214214

215215
# add logging config files
216-
COPY "${LOG4J_CONFIG_OVERRIDE}" "config/${LOG4J_CONFIG_OVERRIDE}"
216+
COPY "*.log4j2.xml" "config/"
217217

218218
# add aws cli & make it owned by labkey user so it can all be deleted after s3 downloads in entrypoint.sh
219219
RUN mkdir -p /usr/src/awsclizip "${LABKEY_HOME}/awsclibin" "${LABKEY_HOME}/aws-cli" \

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,18 @@ The policies can still be overridden by setting them in `application.properties`
1414
The default enforce policy can be disabled by enabling the `ExperimentalFeature.disableEnforceCsp` startup property.
1515

1616
## log4j2.xml
17-
March 2025 brings a new implementation of log4j2.xml. We're now using the default configuration from the [server repo](https://github.com/LabKey/server/blob/develop/server/embedded/src/main/resources/log4j2.xml), and overriding that as needed with the local file identified in the `LOG4J_CONFIG_OVERRIDE` environment variable. By default this is an empty file that makes no changes, which is due to some complications of the Docker `COPY` command. During startup, entrypoint.sh copies the local files into the configs directory after the jar has been opened up.
17+
March 2025 brings a new implementation of log4j2.xml. We're now using the default configuration from the [server repo](https://github.com/LabKey/server/blob/develop/server/embedded/src/main/resources/log4j2.xml), and overriding that as needed with the local file identified in the `LOG4J_CONFIG_OVERRIDE` environment variable. By default this is an empty file that makes no changes, which is due to some complications of the Docker `COPY` command. Any *.log4j2.xml files in the root dir will be copied to the config/ folder in the image when built, which end up in /labkey/config in a running container.
18+
19+
LabKey deployments use the included `labkey.log4j2.xml` to override the server default config, mostly just to set JSON format for console output.
20+
21+
Here are some example env var combinations and their effects:
22+
23+
| env var | result |
24+
| --------------------------------------------------------------------------------- | ------------------------------------------------------ |
25+
| JSON_OUTPUT=true | uses `labkey.log4j2.xml` to set JSON format console output |
26+
| LOG4J_CONFIG_OVERRIDE="labkey.log4j2.xml" | same as above |
27+
| LOG4J_CONFIG_FILE="example.log4j2.xml" | assumes you built your own image with `example.log4j2.xml` in the root dir, and uses that instead of server defaults |
28+
| LOG4J_CONFIG_FILE="example.log4j2.xml" LOG4J_CONFIG_OVERRIDE="labkey.log4j2.xml" | same as above, but also overrides `example.log4j2.xml` with contents of `labkey.log4j2.xml` |
1829

1930
## Upgrading from 23.11 to 24.3
2031
March 2024 saw [many changes](https://github.com/LabKey/Dockerfile/commits/24.3.0) in an effort to bring this repo in line with LabKey server versioning/releases, starting with v24.3, in which the embedded tomcat version has been upgraded from 9 to 10.

application.properties

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ spring.main.banner-mode=off
1212
spring.application.name=labkey
1313
server.servlet.application-display-name=labkey
1414

15-
# 2024-02-29 - if enabling logging.config setting, the file must exist at runtime or app will error and quit
16-
# - if logging.config and LOG4J_CONFIG_FILE env var are set differently, LOG4J_CONFIG_FILE wins
17-
# logging.config=${$LOG4J_CONFIG_FILE:log4j2.xml}
18-
1915
# logging.pattern.console=
2016
logging.pattern.console=%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} E %clr(%-5.5p) %clr(%5.5replace(%p){'.+', ${PID:-}}){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(${LOGGER_PATTERN:-%-40.40logger{39}}){cyan} %clr(:){faint} %m%n%wEx
2117

entrypoint.sh

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,14 +224,18 @@ main() {
224224

225225
sed -i "s/@@encryptionKey@@/${LABKEY_EK}/" config/application.properties
226226

227-
# TODO: do we need the JSON check anymore? should we just take the override if it is set?
228-
# Check if we want JSON output, we are using the base log4j2.xml config, and have an override config to use
229-
if [ "${JSON_OUTPUT}" = "true" ] && [ "${LOG4J_CONFIG_FILE}" = "log4j2.xml" ] && [ -s "config/${LOG4J_CONFIG_OVERRIDE}" ]; then
230-
echo "JSON_OUTPUT==true && LOG4J_CONFIG_FILE==log4j2.xml && LOG4J_CONFIG_OVERRIDE is set, so updating application.properties and log4j2.xml to output JSON to console"
227+
# Check if we want JSON output, we are using the base log4j2.xml config
228+
if [ "${JSON_OUTPUT}" = "true" ] && [ "${LOG4J_CONFIG_FILE}" = "log4j2.xml" ]; then
229+
echo "JSON_OUTPUT==true && LOG4J_CONFIG_FILE==log4j2.xml, so using the base log4j2.xml with labkey.log4j2.xml overrides, to send JSON output to console"
230+
LOG4J_CONFIG_FILE="log4j2.xml, config/labkey.log4j2.xml"
231+
echo "Log4j configuration files: $LOG4J_CONFIG_FILE"
232+
# if the override file exists and isn't empty, use that to override whatever was set in LOG4J_CONFIG_FILE (which might still be server default of log4j2.xml)
233+
elif [ -f "config/${LOG4J_CONFIG_OVERRIDE}" ] && [ -s "config/${LOG4J_CONFIG_OVERRIDE}" ]; then
234+
echo "LOG4J_CONFIG_OVERRIDE==${LOG4J_CONFIG_OVERRIDE}, so using that to override default settings in LOG4J_CONFIG_FILE (${LOG4J_CONFIG_FILE})"
231235
LOG4J_CONFIG_FILE="${LOG4J_CONFIG_FILE:=log4j2.xml},config/${LOG4J_CONFIG_OVERRIDE}"
232236
echo "Log4j configuration files: $LOG4J_CONFIG_FILE"
233237
else
234-
echo "saw JSON_OUTPUT=$JSON_OUTPUT and LOG4J_CONFIG_FILE=$LOG4J_CONFIG_FILE and LOG4J_CONFIG_OVERRIDE=$LOG4J_CONFIG_OVERRIDE"
238+
echo "saw JSON_OUTPUT=$JSON_OUTPUT and LOG4J_CONFIG_FILE=$LOG4J_CONFIG_FILE and LOG4J_CONFIG_OVERRIDE=$LOG4J_CONFIG_OVERRIDE (which, if defined, was empty)"
235239
fi
236240

237241
export DD_JAVA_AGENT=""

labkey.log4j2.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
22

3-
<Configuration packages="org.labkey.api.util,org.labkey.embedded">
3+
<Configuration>
44

55
<Appenders>
66
<Console name="CONSOLE" target="SYSTEM_OUT">

quickstart_envs.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# example minimal set of environment variables to get started - see readme for additional envs you may wish to set
44

55
# embedded tomcat LabKey .jar version to build container with
6-
export LABKEY_VERSION="25.3"
6+
export LABKEY_VERSION="25.7"
77

88
# minimal SMTP settings
99
export SMTP_HOST="localhost"

0 commit comments

Comments
 (0)