applog

Log | Files | Refs | README

applog.sh (2224B)


      1 #!/usr/bin/env bash
      2 
      3 FILTER="$1"
      4 
      5 if [[ -z "$FILTER" ]]; then
      6     echo "Usage: $(basename "$0") <bundle-id-prefix|process-name>"
      7     echo ""
      8     echo "  Examples:"
      9     echo "    $(basename "$0") com.mycompany.myapp"
     10     echo "    $(basename "$0") MyApp"
     11     exit 1
     12 fi
     13 
     14 RED=$'\033[0;31m'
     15 YELLOW=$'\033[0;33m'
     16 CYAN=$'\033[0;36m'
     17 GREEN=$'\033[0;32m'
     18 DIM=$'\033[2m'
     19 RESET=$'\033[0m'
     20 
     21 SEP="${DIM}────────────────────────────────────────${RESET}"
     22 
     23 cleanup() {
     24     printf "\n%s[applog] Stopped.%s\n" "$DIM" "$RESET"
     25     exit 0
     26 }
     27 
     28 trap cleanup SIGINT SIGTERM
     29 
     30 printf "%s[applog] Filtering for '%s'. Ctrl+C to stop.%s\n\n" "$DIM" "$FILTER" "$RESET"
     31 
     32 # System daemons that reference app bundle IDs as incidental observers, not direct participants
     33 BLOCKLIST_RE='^(runningboardd|lsd|trustd|aggregated|tccd|dasd|symptomsd|swcd|calaccessd|mobileassetd|fairplayd|statusbarserver|contextstore|assertiond|thermalmonitord|watchdogd|powerd|logd|notifyd|configd|launchd|mDNSResponder)$'
     34 
     35 idevicesyslog 2>/dev/null | while IFS= read -r line; do
     36     [[ "$line" != *"$FILTER"* ]] && continue
     37 
     38     # Extract process name (stop at '(' or '[' — handles both "proc[sub][pid]" and "proc(sub)[pid]")
     39     # idevicesyslog format: "Mon DD HH:MM:SS.ssssss processname(subsystem)[pid] <Level>: msg"
     40     if [[ "$line" =~ ^[A-Za-z]{3}[[:space:]]+[0-9]+[[:space:]]+[0-9:.]+[[:space:]]+([^[:space:]\[\(]+) ]]; then
     41         [[ "${BASH_REMATCH[1]}" =~ $BLOCKLIST_RE ]] && continue
     42     fi
     43 
     44     # Colorize by <Level>: field; show all lines regardless of level
     45     if [[ "$line" =~ \<(Error|ERROR|Fault|FAULT)\>: ]]; then
     46         printf "%s%s%s\n%s\n" "$RED" "$line" "$RESET" "$SEP"
     47     elif [[ "$line" =~ \<(Warning|WARNING)\>: ]]; then
     48         printf "%s%s%s\n%s\n" "$YELLOW" "$line" "$RESET" "$SEP"
     49     elif [[ "$line" =~ \<(Notice)\>: ]]; then
     50         printf "%s%s%s\n%s\n" "$CYAN" "$line" "$RESET" "$SEP"
     51     elif [[ "$line" =~ \<(Info)\>: ]]; then
     52         printf "%s%s%s\n%s\n" "$GREEN" "$line" "$RESET" "$SEP"
     53     elif [[ "$line" =~ \<(Debug)\>: ]]; then
     54         printf "%s%s%s\n%s\n" "$DIM" "$line" "$RESET" "$SEP"
     55     else
     56         printf "%s\n%s\n" "$line" "$SEP"
     57     fi
     58 done