Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable optional JSON logging to console #42

Merged
merged 4 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ logging.pattern.console=%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} E %clr(%-5.5p)
logging.level.root=WARN

# custom tomcat group
logging.group.tomcat=org.apache.catalina,org.apache.coyote,org.apache.tomcat
logging.group.tomcat=org.apache.catalina, org.apache.coyote, org.apache.tomcat
logging.level.tomcat=${LOG_LEVEL_TOMCAT:OFF}

logging.level.org.apache.coyote.http2=OFF
Expand Down Expand Up @@ -97,20 +97,21 @@ context.validationQuery[0]=${POSTGRES_VALIDATION_QUERY:-SELECT 1}
# context.username[1]=@@extraJdbcUser@@
# context.password[1]=@@extraJdbcPassword@@

# TODO: console access logs w/o symlink
# server.tomcat.accesslog.enabled=true
# server.tomcat.accesslog.directory=/dev
# server.tomcat.accesslog.prefix=stdout
# server.tomcat.accesslog.buffered=false
# server.tomcat.accesslog.suffix=
# server.tomcat.accesslog.pattern=%{org.apache.catalina.AccessLog.RemoteAddr}r %l %u %t "%r" %s %b %D %S "%{Referer}i" "%{User-Agent}i" %{LABKEY.username}s %q

server.tomcat.accesslog.directory=/tmp
# send access logs to stdout:
server.tomcat.accesslog.enabled=true
server.tomcat.accesslog.prefix=access
server.tomcat.accesslog.suffix=.log
server.tomcat.accesslog.rotate=false
server.tomcat.accesslog.pattern=%{org.apache.catalina.AccessLog.RemoteAddr}r %l %u %t "%r" %s %b %D %S "%{Referer}i" "%{User-Agent}i" %{LABKEY.username}s %q
server.tomcat.accesslog.directory=/dev
server.tomcat.accesslog.prefix=stdout
server.tomcat.accesslog.buffered=false
server.tomcat.accesslog.suffix=
server.tomcat.accesslog.file-date-format=

# send access logs to file:
# server.tomcat.accesslog.directory=/tmp
# server.tomcat.accesslog.enabled=true
# server.tomcat.accesslog.prefix=access
# server.tomcat.accesslog.suffix=.log
# server.tomcat.accesslog.rotate=false
# # server.tomcat.accesslog.pattern=%{org.apache.catalina.AccessLog.RemoteAddr}r %l %u %t "%r" %s %b %D %S "%{Referer}i" "%{User-Agent}i" %{LABKEY.username}s %q

server.http2.enabled=true

Expand Down
8 changes: 8 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ services:

- LABKEY_CUSTOM_PROPERTIES_S3_URI=${LABKEY_CUSTOM_PROPERTIES_S3_URI}
- LABKEY_DEFAULT_PROPERTIES_S3_URI=${LABKEY_DEFAULT_PROPERTIES_S3_URI}
- LOG4J_CONFIG_FILE=${LOG4J_CONFIG_FILE-log4j2.xml}
- JSON_OUTPUT=${JSON_OUTPUT-false}
- SLEEP=${SLEEP:-0}

pg-community:
Expand Down Expand Up @@ -189,6 +191,8 @@ services:

- LABKEY_CUSTOM_PROPERTIES_S3_URI=${LABKEY_CUSTOM_PROPERTIES_S3_URI}
- LABKEY_DEFAULT_PROPERTIES_S3_URI=${LABKEY_DEFAULT_PROPERTIES_S3_URI}
- LOG4J_CONFIG_FILE=${LOG4J_CONFIG_FILE-log4j2.xml}
- JSON_OUTPUT=${JSON_OUTPUT-false}
- SLEEP=${SLEEP:-0}

pg-allpg:
Expand Down Expand Up @@ -295,6 +299,8 @@ services:

- LABKEY_CUSTOM_PROPERTIES_S3_URI=${LABKEY_CUSTOM_PROPERTIES_S3_URI}
- LABKEY_DEFAULT_PROPERTIES_S3_URI=${LABKEY_DEFAULT_PROPERTIES_S3_URI}
- LOG4J_CONFIG_FILE=${LOG4J_CONFIG_FILE-log4j2.xml}
- JSON_OUTPUT=${JSON_OUTPUT-false}
- SLEEP=${SLEEP:-0}

pg-enterprise:
Expand Down Expand Up @@ -401,6 +407,8 @@ services:

- LABKEY_CUSTOM_PROPERTIES_S3_URI=${LABKEY_CUSTOM_PROPERTIES_S3_URI}
- LABKEY_DEFAULT_PROPERTIES_S3_URI=${LABKEY_DEFAULT_PROPERTIES_S3_URI}
- LOG4J_CONFIG_FILE=${LOG4J_CONFIG_FILE-log4j2.xml}
- JSON_OUTPUT=${JSON_OUTPUT-false}
- SLEEP=${SLEEP:-0}

pg-lims_starter:
Expand Down
23 changes: 20 additions & 3 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ keystore_format="${TOMCAT_KEYSTORE_FORMAT:-}"

LABKEY_CUSTOM_PROPERTIES_S3_URI="${LABKEY_CUSTOM_PROPERTIES_S3_URI:=none}"
LABKEY_DEFAULT_PROPERTIES_S3_URI="${LABKEY_DEFAULT_PROPERTIES_S3_URI:=none}"

# set below to 'server/labkeywebapp/WEB-INF/classes/log4j2.xml' to use embedded tomcat version
LOG4J_CONFIG_FILE="${LOG4J_CONFIG_FILE:='log4j2.xml'}"

# below assumes using local log4j2.xml file, as the embedded version is not available for edits until after server is running
JSON_OUTPUT="${JSON_OUTPUT:-false}"

SLEEP="${SLEEP:=0}"

main() {
Expand Down Expand Up @@ -134,8 +141,8 @@ main() {
# rm -rf awsclibin aws-cli
unset AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN

echo "sleeping for $SLEEP seconds..."
sleep $SLEEP
# echo "sleeping for $SLEEP seconds..."
# sleep $SLEEP

for prop_file in server/startup/*.properties; do
envsubst < "$prop_file" > "${prop_file}.tmp" \
Expand All @@ -146,6 +153,7 @@ main() {
keystore_pass="$(random_string 64)"
fi

# below only works if server.tomcat.accesslog settings in application.properties are set to go to file instead of stdout
if [ -n "$TOMCAT_ENABLE_ACCESS_LOG" ]; then
ln -sfv /proc/1/fd/1 /tmp/access.log
fi
Expand Down Expand Up @@ -209,6 +217,15 @@ main() {
unset LABKEY_CREATE_INITIAL_USER LABKEY_CREATE_INITIAL_USER_APIKEY LABKEY_INITIAL_USER_APIKEY LABKEY_INITIAL_USER_EMAIL LABKEY_INITIAL_USER_GROUP LABKEY_INITIAL_USER_ROLE
unset LABKEY_EK SLEEP

if [ "$JSON_OUTPUT" = "true" ] && [ "$LOG4J_CONFIG_FILE" = "log4j2.xml" ]; then
echo "JSON_OUTPUT==true && LOG4J_CONFIG_FILE==log4j2.xml, so updating application.properties and log4j2.xml to output JSON to console"
sed -i '/<!-- p=priority c=category d=datetime t=thread m=message n=newline -->/d' $LOG4J_CONFIG_FILE
sed -i 's/<PatternLayout.*\/>/<JSONLayout compact="true" eventEol="true" properties="true" stacktraceAsString="true" \/>/' $LOG4J_CONFIG_FILE
sed -i 's/^logging.pattern.console/# logging.pattern.console/' config/application.properties
else
echo "saw JSON_OUTPUT=$JSON_OUTPUT and LOG4J_CONFIG_FILE=$LOG4J_CONFIG_FILE"
fi

# shellcheck disable=SC2086
exec java \
\
Expand Down Expand Up @@ -237,7 +254,7 @@ main() {
-Dlogback.debug="$debug_string" \
\
-Dlog4j.debug="$debug_string" \
-Dlog4j.configurationFile=log4j2.xml \
-Dlog4j.configurationFile="$LOG4J_CONFIG_FILE" \
\
-Dorg.apache.catalina.startup.EXIT_ON_INIT_FAILURE=true \
\
Expand Down
172 changes: 133 additions & 39 deletions log4j2.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
<?xml version="1.0" encoding="UTF-8" ?>

<Configuration packages="org.labkey.api.util">

<Appenders>
<Console name="CONSOLE" target="SYSTEM_OUT">
<PatternLayout
pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} I %-5.5p %5.5L --- [%15.15t] ${env:LOGGER_PATTERN} : %m%n%xEx"
/>
<!-- p=priority c=category d=datetime t=thread m=message n=newline -->
<PatternLayout pattern="%-5p %-24.24c{1} %d{ISO8601} %24.24t : %m%n" />

<!-- <JSONLayout compact="true" eventEol="true" properties="true" stacktraceAsString="true" /> -->

</Console>

<RollingFile name="ERRORS"
Expand Down Expand Up @@ -139,20 +142,108 @@

<Loggers>

<Logger name="org.apache" level="${env:LOG_LEVEL_TOMCAT:-OFF}"/>

<Logger name="org.springframework.web" level="${env:LOG_LEVEL_SPRING_WEB:-OFF}"/>

<!-- category for server side script messages -->
<Logger name="org.labkey.api.script.ScriptService.Console" level="${env:LOG_LEVEL_API_SETTINGS:-INFO}">
<AppenderRef ref="SessionAppender"/>
</Logger>


<!-- category for Mule messages -->
<Logger name="org.mule.MuleManager" level="info"/>

<!--
<Logger name="org.labkey.pipeline.mule.transformers" level="debug"/>
-->

<!-- category for jasper messages -->
<Logger name="org.apache.jasper" level="warn"/>

<!-- application classes -->
<Logger name="org.fhcrc" level="info"/>


<Logger name="org.labkey" level="${env:LOG_LEVEL_LABKEY_DEFAULT:-INFO}">
<AppenderRef ref="CONSOLE"/>
<AppenderRef ref="LABKEY"/>
</Logger>

<!-- uncomment to enable 'DEBUG' level on external SAML libraries to troubleshoot.
Note: you will also have to set dependency on slf4j lib in saml/build.gradle - uncomment 'slf4j' external libraries and build
<Logger name="org.opensaml" level="DEBUG">
<AppenderRef ref="CONSOLE"/>
<AppenderRef ref="LABKEY"/>
</Logger>

<Logger name="org.apache.xml.security" level="DEBUG">
<AppenderRef ref="CONSOLE"/>
<AppenderRef ref="LABKEY"/>
</Logger> -->

<Logger name="mondrian." level="info" />

<!--
<Logger name="org.labkey.wiki" level="debug"/>
-->

<!--
<Logger name="org.labkey.api.action.SpringActionController" level="debug"/>
-->

<!-- only show errors from PipelineJob output -->
<Logger name="org.labkey.api.pipeline.PipelineJob" level="error">
<AppenderRef ref="CONSOLE"/>
</Logger>

<!-- don't need to log PDFBox errors (e.g., FlateFilter, PDCIDFontType2) -->
<Logger name="org.apache.pdfbox" level="fatal"/>

<!-- this is a very verbose logger for security/permissions checking -->
<!--
<Logger name="org.labkey.api.security.SecurityManager" level="debug"/>
-->

<!-- Add specific module packages or classes to get debug information about
features you are working on. -->

<!--
<Logger name="org.labkey.api.data.Table" level="debug"/>
-->

<Logger name="org.labkey.api.data"/>

<Logger name="org.labkey.api.dataiterator"/>

<Logger name="org.labkey.docker">
<level value="info"/>
</Logger>

<Logger name="org.labkey.rstudio" level="info"/>


<!--
<Logger name="org.labkey.api.cache" level="debug"/>
-->

<!--
<Logger name="org.labkey.api.data.TempTableTracker" level="debug"/>
-->

<!--
<Logger name="org.labkey.query" level="debug"/>
-->

<!--
<Logger name="org.labkey.pipeline.mule" level="debug"/>
-->

<!--
<Logger name="org.labkey.search" level="debug"/>
-->

<!--
<Logger name="org.labkey.search.model.LuceneSearchServiceImpl" level="debug"/>
-->

<Logger name="org.labkey.api.util.MemTracker" additivity="false" level="${env:LOG_LEVEL_LABKEY_DEFAULT:-DEBUG}">
<AppenderRef ref="LABKEYMemory"/>
</Logger>
Expand All @@ -161,18 +252,15 @@
<AppenderRef ref="THREAD_DUMP"/>
</Logger>



<!--
set to DEBUG for startup property messages set to TRACE for values
<Logger name="org.labkey.api.view.ViewServlet" additivity="false" level="debug"/>
-->
<Logger name="org.labkey.api.module.ModuleLoader"
level="${env:LOG_LEVEL_API_MODULELOADER:-WARN}"
/>

<Logger name="org.labkey.api.settings"
level="${env:LOG_LEVEL_API_SETTINGS:-WARN}"
/>
<!--
<Logger name="org.labkey" level="debug">
<AppenderRef ref="SESSION"/>
</Logger>
-->

<Logger name="org.labkey.core.admin.ActionsTsvWriter" additivity="false" level="${env:LOG_LEVEL_LABKEY_DEFAULT:-INFO}">
<AppenderRef ref="ACTION_STATS"/>
Expand All @@ -187,38 +275,44 @@
<AppenderRef ref="CONSOLE"/>
</Logger>

<!--
Other audit event types include, but are not limited to:
AppPropsEvent
AssayPublishAuditEvent
AttachmentAuditEvent
AuthenticationProviderConfiguration
ClientAPIActions
ContainerAuditEvent
DatasetAuditEvent
DomainAuditEvent
ExperimentAuditEvent
FileSystem
FileSystemBatch
GroupAuditEvent
ListAuditEvent
LoggedQuery
MessageAuditEvent
pipelineProtocolEvent
QueryExportAuditEvent
QueryUpdateAuditEvent
SampleTypeAuditEvent
SearchAuditEvent
SelectQuery
To enable logging of all events, set the level for the org.labkey.audit.event to
something other than "OFF". To enable individual audit event logging, configure the
individual stanza like the one shown below, where you prefix the audit event type
with 'org.labkey.audit.event'. Then set the level to INFO and specify the appenders.
-->
<Logger name="org.labkey.audit.event.UserAuditEvent" additivity="false" level="OFF">
<AppenderRef ref="LABKEY_AUDIT"/>
<AppenderRef ref="CONSOLE"/>
</Logger>



<!-- <Logger name="org.labkey.api.data.DbScope" level="WARN"/>
<Logger name="org.labkey.api.data.SqlScriptExecutor" level="WARN"/>
<Logger name="org.labkey.api.data.SqlScriptManager" level="WARN"/>
<Logger name="org.labkey.api.data.SqlScriptRunner" level="WARN"/>
<Logger name="org.labkey.api.data.JdbcCommand" level="WARN"/>
<Logger name="org.labkey.api.data.ConnectionWrapper" level="WARN"/>
<Logger name="org.labkey.api.module.ModuleLoader" level="ERROR"/>
<Logger name="org.labkey.api.search.SearchService" level="ERROR"/>
<Logger name="org.labkey.api.view.ViewServlet" level="ERROR"/>
<Logger name="org.labkey.api.cache.ehcache" level="WARN"/>
<Logger name="org.labkey.api.data.queryprofiler" level="WARN"/>
<Logger name="org.labkey.core.admin.ActionsTsvWriter" level="WARN"/>
<Logger name="org.labkey.audit" level="ERROR"/>
<Logger name="org.labkey.search" level="ERROR"/>
<Logger name="org.labkey.api.util" level="TRACE"/>
<Logger name="org.labkey.api.exp.xar.LsidUtils" level="WARN"/> -->

<Logger name="org.labkey.api.pipeline" level="${env:LOG_LEVEL_API_PIPELINE:-WARN}">
<AppenderRef ref="CONSOLE"/>
</Logger>
<Logger name="NoOpLogger" level="OFF" additivity="false"/>

<Root level="${env:LOG_LEVEL_DEFAULT:-FATAL}">
<AppenderRef ref="CONSOLE"/>
<AppenderRef ref="ERRORS"/>
</Root>
</Loggers>

</Configuration>