forked from wildfly/wildfly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_logging.sh
58 lines (51 loc) · 1.46 KB
/
check_logging.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash
BASE_BRANCH="${GITHUB_BASE_REF:-main}"
DIFF=$(git diff origin/"$BASE_BRANCH"...HEAD || true)
if [ -z "$DIFF" ]; then
echo "No diff found to analyze."
exit 0
fi
PATTERNS=(
".info(\""
".infof(\""
".warn(\""
".warnf(\""
".error(\""
".errorf(\""
".fatal(\""
".fatalf(\""
"System.out.print"
"System.err.print"
".printStackTrace"
)
ERRORS=""
CURRENT_FILE=""
while IFS= read -r line; do
# Update the current file if a new diff starts
if [[ "$line" =~ ^diff\ --git\ a\/.*\ b\/.* ]]; then
CURRENT_FILE=$(echo "$line" | awk '{print $3}' | sed 's/^a\///')
fi
if [[ "$line" =~ ^\+[^+] ]]; then
# Ignore lines in the test directories
if [[ "$CURRENT_FILE" != *"src/test/"* && "$CURRENT_FILE" != *"testsuite/"* && "$CURRENT_FILE" != *"check_logging.sh"* ]]; then
# Check for any of the patterns, ensuring "//" doesn't precede them
for pattern in "${PATTERNS[@]}"; do
if [[ "$line" == *"$pattern"* ]]; then
# Ensure the pattern is not commented out with "//"
if [[ "$line" != *"//"*"$pattern"* ]]; then
# Capture the error line and its context
ERRORS+="$line\nFile: $CURRENT_FILE\n\n"
fi
fi
done
fi
fi
done <<< "$DIFF"
if [ -n "$ERRORS" ]; then
echo -e "Logging statements found that should be internationalized or converted to a lower log level:\n"
echo -e "$ERRORS"
exit 1
else
echo "No problematic logging statements found."
exit 0
fi