2
0

log 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/usr/bin/env bash
  2. CONTAINER_LOG_PATH="/var/www/html/var/log/";
  3. display_help() {
  4. echo -e "Description:
  5. Tail logs from the Magento var/log folder all and specific logs
  6. Usage:
  7. bin/log <specific_log_files>
  8. Arguments:
  9. specific_log_files If specific_log_files are NOT provided, show all logs. Ex: bin/log system.log cache.log
  10. Options:
  11. -h, --help Display help message"
  12. }
  13. generate_logs_file_path() {
  14. local container_log_path="$1"
  15. shift # This shifts the positional parameters to the left, so $2 becomes $1, $3 becomes $2, etc.
  16. local log_files=("$@")
  17. local log_file_paths=()
  18. for file in "${log_files[@]}"; do
  19. log_file_paths+=("$container_log_path$file")
  20. done
  21. echo "${log_file_paths[@]}"
  22. }
  23. get_all_logs_file_path() {
  24. local logs_location="$1"
  25. bin/docker-compose exec phpfpm ls -p "$logs_location" | grep -v '/$' | sed "s|^|$logs_location|"
  26. }
  27. if [[ $1 == "-h" || $1 == "--help" ]]; then
  28. display_help
  29. elif [[ -z $1 ]]; then
  30. mapfile -t all_logs_file_path < <(get_all_logs_file_path "$CONTAINER_LOG_PATH")
  31. bin/docker-compose exec phpfpm tail -f "${all_logs_file_path[@]}"
  32. else
  33. mapfile -t logs_file_path < <(generate_logs_file_path "$CONTAINER_LOG_PATH" "$@")
  34. bin/docker-compose exec phpfpm tail -f "${logs_file_path[@]}"
  35. fi