Files
distribution_erp/smart-logs.sh
T
chpark 3e135041ac Initial commit: ILSHIN PLM 프로젝트 소스 코드
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 17:49:38 +09:00

139 lines
5.5 KiB
Bash
Executable File

#!/bin/bash
# 스마트 로그 뷰어 (pretty-logs + clean-logs 통합)
echo -e "\033[1;36m🎨 Smart Log Viewer\033[0m"
echo -e "\033[1;36m===================\033[0m"
# 컨테이너 확인
CONTAINER_NAME=$(docker ps --format "table {{.Names}}" | grep plm-ilshin | head -1)
if [ -z "$CONTAINER_NAME" ]; then
echo -e "\033[1;31m❌ No PLM container running\033[0m"
echo -e "\033[1;33m💡 Start with: ./start-debug.sh\033[0m"
exit 1
fi
echo -e "\033[1;32m🐳 Container: $CONTAINER_NAME\033[0m"
echo -e "\033[1;35m⏰ Started: $(date)\033[0m"
echo ""
# 메뉴 표시
echo -e "\033[1;36m🔍 Choose log view:\033[0m"
echo -e "\033[1;31m 1) 🔴 Errors & Exceptions only\033[0m"
echo -e "\033[1;33m 2) 🟡 Warnings & Errors\033[0m"
echo -e "\033[1;32m 3) 📱 Application logs (clean, auto-clear)\033[0m"
echo -e "\033[1;34m 4) 🗃️ SQL queries only\033[0m"
echo -e "\033[1;35m 5) 🎯 Custom keyword search\033[0m"
echo -e "\033[1;37m 6) 📋 Recent summary (last 20)\033[0m"
echo -e "\033[1;36m 7) 🌈 All logs (with auto-clear)\033[0m"
echo ""
read -p "$(echo -e '\033[1;36mChoose option (1-7): \033[0m')" choice
# 자동 클리어 기능이 있는 로그 포맷팅 함수
format_log_with_autoclear() {
local log_count=0
local max_logs=50
while IFS= read -r line; do
# 자동 클리어 (옵션 3, 7에서만)
if [[ "$1" == "autoclear" ]] && [ $log_count -ge $max_logs ]; then
clear
echo -e "\033[1;36m🎨 Smart Log Viewer (Auto-cleared)\033[0m"
echo -e "\033[1;32m🐳 $CONTAINER_NAME\033[0m"
echo -e "\033[0;90m(Press Ctrl+C to stop)\033[0m"
echo ""
log_count=0
fi
# 타임스탬프 추출
if [[ $line =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2} ]]; then
timestamp=$(echo "$line" | cut -d' ' -f1 | cut -dT -f2 | cut -d. -f1)
content=$(echo "$line" | cut -d' ' -f2-)
else
timestamp=$(date '+%H:%M:%S')
content="$line"
fi
# 로그 레벨에 따른 컬러링
if [[ $content == *"ERROR"* ]] || [[ $content == *"Exception"* ]] || [[ $content == *"Failed"* ]]; then
echo -e "\033[1;31m[$timestamp] 🔴 $content\033[0m"
elif [[ $content == *"WARN"* ]] || [[ $content == *"Warning"* ]]; then
echo -e "\033[1;33m[$timestamp] 🟡 $content\033[0m"
elif [[ $content == *"INFO"* ]] || [[ $content == *"Started"* ]] || [[ $content == *"Completed"* ]]; then
echo -e "\033[1;32m[$timestamp] 📗 $content\033[0m"
elif [[ $content == *"DEBUG"* ]]; then
echo -e "\033[1;36m[$timestamp] 🔍 $content\033[0m"
elif [[ $content == *"SELECT"* ]] || [[ $content == *"INSERT"* ]] || [[ $content == *"UPDATE"* ]] || [[ $content == *"DELETE"* ]]; then
echo -e "\033[1;35m[$timestamp] 🗃️ $content\033[0m"
else
echo -e "\033[0;37m[$timestamp] 📄 $content\033[0m"
fi
log_count=$((log_count + 1))
done
}
# 일반 로그 포맷팅 함수 (자동 클리어 없음)
format_log() {
format_log_with_autoclear "normal"
}
# 선택에 따른 실행
case $choice in
1)
clear
echo -e "\033[1;31m🔴 Showing ERRORS & EXCEPTIONS...\033[0m"
echo -e "\033[0;90m(Press Ctrl+C to stop)\033[0m"
echo ""
docker logs -f --timestamps "$CONTAINER_NAME" 2>&1 | grep -i -E "(error|exception|failed|fatal)" | format_log
;;
2)
clear
echo -e "\033[1;33m🟡 Showing WARNINGS & ERRORS...\033[0m"
echo -e "\033[0;90m(Press Ctrl+C to stop)\033[0m"
echo ""
docker logs -f --timestamps "$CONTAINER_NAME" 2>&1 | grep -i -E "(error|exception|failed|warn|fatal)" | format_log
;;
3)
clear
echo -e "\033[1;32m📱 Showing APPLICATION logs (clean, auto-clear)...\033[0m"
echo -e "\033[0;90m(Auto-clears every 50 lines, Press Ctrl+C to stop)\033[0m"
echo ""
docker logs -f --timestamps "$CONTAINER_NAME" 2>&1 | \
grep -v -E "(Starting ProtocolHandler|Server startup|Catalina|AprLifecycleListener|HostConfig|StandardService|DefaultAnnotationHandlerMapping|DispatcherServlet.*processing|DEBUG)" | \
format_log_with_autoclear "autoclear"
;;
4)
clear
echo -e "\033[1;35m🗃️ Showing SQL QUERIES...\033[0m"
echo -e "\033[0;90m(Press Ctrl+C to stop)\033[0m"
echo ""
docker logs -f --timestamps "$CONTAINER_NAME" 2>&1 | grep -i -E "(select|insert|update|delete|query)" | format_log
;;
5)
read -p "$(echo -e '\033[1;35mEnter search keyword: \033[0m')" keyword
clear
echo -e "\033[1;35m🎯 Searching for: '$keyword'...\033[0m"
echo -e "\033[0;90m(Press Ctrl+C to stop)\033[0m"
echo ""
docker logs -f --timestamps "$CONTAINER_NAME" 2>&1 | grep -i "$keyword" | format_log
;;
6)
clear
echo -e "\033[1;37m📋 Recent LOG SUMMARY (last 20):\033[0m"
echo ""
docker logs --tail 20 --timestamps "$CONTAINER_NAME" 2>&1 | format_log
;;
7)
clear
echo -e "\033[1;36m🌈 Showing ALL logs (with auto-clear)...\033[0m"
echo -e "\033[0;90m(Auto-clears every 50 lines, Press Ctrl+C to stop)\033[0m"
echo ""
docker logs -f --timestamps "$CONTAINER_NAME" 2>&1 | format_log_with_autoclear "autoclear"
;;
*)
echo -e "\033[1;31m❌ Invalid choice\033[0m"
exit 1
;;
esac