Skip to content

Commit

Permalink
WFLY-19605 Add a CI job to check for non-i18n INFO/WARN/ERROR logging
Browse files Browse the repository at this point in the history
  • Loading branch information
RanabirChakraborty committed Aug 8, 2024
1 parent 9441016 commit 987c363
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/check_logging.yml
Original file line number Diff line number Diff line change
@@ -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
49 changes: 49 additions & 0 deletions check_logging.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 987c363

Please sign in to comment.