blob: 80de562b2b6270a5ee4f4008202a4445561b46b3 [file] [log] [blame]
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved.
This program and the accompanying materials are made available under the
terms of the Eclipse Public License v. 2.0, which is available at
http://www.eclipse.org/legal/epl-2.0.
This Source Code may also be made available under the following Secondary
Licenses when the conditions for such availability set forth in the
Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
version 2 with the GNU Classpath Exception, which is available at
https://www.gnu.org/software/classpath/license.html.
SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
-->
<!--
Contributor(s): Dies Koper (Fujitsu Ltd.)
-->
<project name="utils" basedir=".">
<target name="check-logged-messages" description="Check server.log for message issues">
<!--
Process:
- set up regexp for each type of issue (using <property> instead of <regexp>
as latter cannot be used in <replaceregex>)
- load exclude list (add -Dlog.msg.excl.path=other-list.txt to load another
list (or empty file to include all messages)
- copy server.log to temp file while removing messages from exclude list
- search temp file for each type of issue and report
- at the end, fail if any issue found
-->
<property file="../build.properties"/>
<property name="server.log.path" location="${glassfish.home}/domains/domain1/logs/server.log"/>
<property name="log.msg.excl.path" location="gfproject/log_msg_excl.txt"/>
<tempfile property="log.msg.tmp.path" destdir="../test-output" prefix="server_log_filtered" deleteonexit="true"/>
<!-- prepare regex patterns to detect missing Ids, typos, etc. -->
<!-- like in IT 11637 -->
<property name="msg_with_id" value="\[#\|\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d\.\d\d\d\D\d\d\d\d\|(INFO|WARNING|SEVERE)\|[\w.]+?\|.+?\|.*?\|\w+\d+\s?:\s?.*?\|#\]"/>
<!-- like in IT 11627, 11545, 6988, 7004, 7001, 9883, 9910, 9147, 10998 -->
<property name="msg_key" value="\[#\|\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d\.\d\d\d\D\d\d\d\d\|(INFO|WARNING|SEVERE)\|[\w.]+?\|.+?\|.*?\|(\w+\.)+\w*\|#\]"/>
<!-- like in IT 7141 -->
<property name="msg_not_found" value="\[#\|\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d\.\d\d\d\D\d\d\d\d\|(INFO|WARNING|SEVERE)\|[\w.]+?\|.+?\|.*?\|No local string defined\|#\]"/>
<!-- like in IT 9922, 11542 -->
<property name="bundle_not_found_msg" value="\[#\|\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d\.\d\d\d\D\d\d\d\d\|(INFO|WARNING|SEVERE)\|[\w.]+?\|.+?\|.*?\|Can not find resource bundle for this logger\.\|#\]"/>
<!-- like in IT 9266, 8285 -->
<property name="null_or_empty_msg" value="\[#\|\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d\.\d\d\d\D\d\d\d\d\|(INFO|WARNING|SEVERE)\|[\w.]+?\|.+?\|.*?\|(null|The log message is null)?\|#\]"/>
<!-- like in IT 10884 -->
<property name="msg_common_typos" value="\[#\|\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d\.\d\d\d\D\d\d\d\d\|(INFO|WARNING|SEVERE)\|[\w.]+?\|.+?\|.*?\|.*?(occure| dont ).*?\|#\]"/>
<!-- like in IT 7053, 6990, 6989, 7002, 10038, 10769 -->
<property name="msg_unsubst_param" value="\[#\|\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d\.\d\d\d\D\d\d\d\d\|(INFO|WARNING|SEVERE)\|[\w.]+?\|.+?\|.*?\|.*?\{\d\}.*?\|#\]"/>
<!-- like in IT 9896, 9212 -->
<property name="msg_double_apos" value="\[#\|\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d\.\d\d\d\D\d\d\d\d\|(INFO|WARNING|SEVERE)\|[\w.]+?\|.+?\|.*?\|.*?\w''\w.*?\|#\]"/>
<!-- example msg for reference to understand above regex's:
[#|2010-05-15T15:07:39.453+1000|INFO|glassfishv3.0|javax.enterprise.resource.jta.com.sun.enterprise.transaction|_ThreadID=15;_ThreadName=Thread-1;|DTX5019: Using [com.sun.enterprise.transaction.jts.JavaEETransactionManagerJTSDelegate] as the delegate|#]
[#|yyyy-mm-ddTHH:mm:ss:SSS-ZZZZ|Level|ProductId|Logger Name|Name Value Pairs|MsgId: Message|#]
-->
<echo>Checking messages in:
${server.log.path}
</echo>
<!-- load file that lists excluded loggers, messages, message fragments and convert to regex 'OR' pattern -->
<loadfile srcfile="${log.msg.excl.path}" property="log_msg_excl" failonerror="false">
<filterchain>
<striplinecomments>
<comment value="#"/>
</striplinecomments>
<ignoreblank/>
<prefixlines prefix="|"/>
<striplinebreaks/>
</filterchain>
</loadfile>
<!-- Following regex is explained here http://www.regular-expressions.info/completelines.html -->
<property name="excl_msgs" value="^(?:(?!dummymsg${log_msg_excl}).)*$"/>
<!--echo>excl_msgs: ${excl_msgs}</echo-->
<!-- copy log file, filter excluded loggers and messages (start-up, stacktrace, etc.) -->
<!-- further checks are based on this file -->
<copy file="${server.log.path}" tofile="${log.msg.tmp.path}" overwrite="true">
<filterchain>
<linecontainsregexp>
<regexp pattern="${excl_msgs}"/>
</linecontainsregexp>
<ignoreblank/>
<!-- also exclude lines that do not start with [#|nnnn as they are probably
multi-line messages, stacktraces, etc. continuing from the previous line -->
<linecontainsregexp>
<regexp pattern="^\[#\|\d\d\d\d.*"/>
</linecontainsregexp>
</filterchain>
</copy>
<!-- extract and report message keys and other issues-->
<filter-log-file srcfile="${log.msg.tmp.path}" property="lines_with_msg_key" regexp="${msg_key}">
* Message keys logged instead of message:
</filter-log-file>
<filter-log-file srcfile="${log.msg.tmp.path}" property="lines_with_msg_unsubst_param" regexp="${msg_unsubst_param}">
* Parameter marker not substituted with value:
</filter-log-file>
<filter-log-file srcfile="${log.msg.tmp.path}" property="lines_with_bundle_not_found_msg" regexp="${bundle_not_found_msg}">
* Bundle not found:
</filter-log-file>
<filter-log-file srcfile="${log.msg.tmp.path}" property="lines_with_msg_not_found" regexp="${msg_not_found}">
* Messages not found in message bundle:
</filter-log-file>
<filter-log-file srcfile="${log.msg.tmp.path}" property="lines_with_null_or_empty_msg" regexp="${null_or_empty_msg}">
* No message:
</filter-log-file>
<filter-log-file srcfile="${log.msg.tmp.path}" property="lines_with_msg_common_typos" regexp="${msg_common_typos}">
* Messages with common typo's ('occured' with one 'r', 'dont' missing apostrophe, etc.):
</filter-log-file>
<filter-log-file srcfile="${log.msg.tmp.path}" property="lines_with_msg_double_apos" regexp="${msg_double_apos}">
* Messages with double apostrophes:
</filter-log-file>
<!-- filter excluded loggers and messages for correct messages and already reported issues to find remaining issues -->
<loadfile srcfile="${log.msg.tmp.path}" property="remaining_messages">
<filterchain>
<replaceregex pattern="${msg_with_id}"/>
<replaceregex pattern="${msg_key}"/>
<replaceregex pattern="${msg_not_found}"/>
<replaceregex pattern="${bundle_not_found_msg}"/>
<replaceregex pattern="${null_or_empty_msg}"/>
<ignoreblank/>
</filterchain>
</loadfile>
<property name="remaining_messages" value="(none)"/>
<echo>
* Messages with no proper message Id:
${remaining_messages}
</echo>
<condition property="cond-is-true">
<not>
<and>
<equals arg1="(none)" arg2="${lines_with_msg_key}"/>
<equals arg1="(none)" arg2="${lines_with_msg_unsubst_param}"/>
<equals arg1="(none)" arg2="${lines_with_bundle_not_found_msg}"/>
<equals arg1="(none)" arg2="${lines_with_null_or_empty_msg}"/>
<equals arg1="(none)" arg2="${lines_with_msg_not_found}"/>
<equals arg1="(none)" arg2="${lines_with_msg_common_typos}"/>
<equals arg1="(none)" arg2="${lines_with_msg_double_apos}"/>
<equals arg1="(none)" arg2="${remaining_messages}"/>
</and>
</not>
</condition>
<antcall target="pass"/>
<antcall target="fail"/>
</target>
<target name="pass" unless="cond-is-true">
<echo message="======================================================================"/>
<echo message="PASSED: check-logged-messages"/>
<echo message="======================================================================"/>
</target>
<target name="fail" if="cond-is-true">
<echo message="======================================================================"/>
<echo message="FAILED: check-logged-messages"/>
<echo message="Issues found in one or more messages (see results above)."/>
<echo message="Please address them, or if the message should be left as-is,"/>
<echo message="add it to the exclusion list with details why it should be excluded:"/>
<echo message="${log.msg.excl.path}"/>
<echo message="======================================================================"/>
</target>
<macrodef name="filter-log-file">
<attribute name="srcfile" description="path to server.log file"/>
<attribute name="property" description="name of property to store result in"/>
<attribute name="regexp" description="regular expression of lines to include"/>
<text name="text" description="caption for result"/>
<sequential>
<loadfile srcfile="@{srcfile}" property="@{property}">
<filterchain>
<linecontainsregexp>
<regexp pattern="@{regexp}"/>
</linecontainsregexp>
</filterchain>
</loadfile>
<property name="@{property}" value="(PASSED: no problems found)"/>
<echo message="@{text}${@{property}}${line.separator}"/>
</sequential>
</macrodef>
</project>