diff --git a/.github/workflows/check_logging.yml b/.github/workflows/check_logging.yml new file mode 100644 index 000000000000..b3c100ca4f29 --- /dev/null +++ b/.github/workflows/check_logging.yml @@ -0,0 +1,16 @@ +name: Check PR Logging + +on: + push: + branches: + - WFLY-19605 + +jobs: + check-logging: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Run logging check + run: ./check_logging.sh \ No newline at end of file diff --git a/check_logging.sh b/check_logging.sh new file mode 100644 index 000000000000..cef75a84561e --- /dev/null +++ b/check_logging.sh @@ -0,0 +1,49 @@ +#!/bin/bash + +# Fetch the PR diff +DIFF=$(git diff origin/WFLY-19605...HEAD) + +# Define the patterns to search for +PATTERNS=( + ".info(" + ".infof(" + ".warn(" + ".warnf(" + ".error(" + ".errorf(" + ".fatal(" + ".fatalf(" + "System.out.print" + "System.err.print" + ".printStackTrace" +) + +# Loop through the diff and check for patterns +ERROR_FOUND=0 +while IFS= read -r line; do + # Check if the line is an added line + if [[ "$line" =~ ^\+[^+] ]]; then + # Ignore test directories + if [[ "$line" != *"src/test/"* ]] && [[ "$line" != *"testsuite/"* ]]; then + # Ignore comments + if [[ "$line" != *"//"* ]]; then + # Check for any of the patterns + for pattern in "${PATTERNS[@]}"; do + if [[ "$line" == *"$pattern"* ]]; then + ERROR_FOUND=1 + break 2 + fi + done + fi + fi + fi +done <<< "$DIFF" + +# Fail if any patterns are found +if [ "$ERROR_FOUND" -eq 1 ]; then + echo "Logging statements found that should be internationalized or converted to a lower log level." + exit 1 +else + echo "No problematic logging statements found." + exit 0 +fi