Browse Source

Merge pull request #1060 from bbakalov/bin-log-command

Mark Shust 1 năm trước cách đây
mục cha
commit
defde77b97
3 tập tin đã thay đổi với 48 bổ sung0 xóa
  1. 1 0
      README.md
  2. 1 0
      compose/Makefile
  3. 46 0
      compose/bin/log

+ 1 - 0
README.md

@@ -290,6 +290,7 @@ It is recommended to keep your root docker config files in one repository, and y
 - `bin/fixperms`: This will fix filesystem permissions within the container.
 - `bin/grunt`: Run the grunt binary. Ex. `bin/grunt exec`
 - `bin/install-php-extensions`: Install PHP extension in the container. Ex. `bin/install-php-extensions sourceguardian`
+- `bin/log`: Monitor the Magento log files. Pass no params to tail all files. Ex. `bin/log debug.log`
 - `bin/magento`: Run the Magento CLI. Ex: `bin/magento cache:flush`
 - `bin/mftf`: Run the Magento MFTF. Ex: `bin/mftf build:project`
 - `bin/mysql`: Run the MySQL CLI with database config from `env/db.env`. Ex. `bin/mysql -e "EXPLAIN core_config_data"` or`bin/mysql < magento.sql`

+ 1 - 0
compose/Makefile

@@ -36,6 +36,7 @@ help:
 	@echo "$(call format,fixowns,'This will fix filesystem ownerships within the container.')"
 	@echo "$(call format,fixperms,'This will fix filesystem permissions within the container.')"
 	@echo "$(call format,grunt,'Run the grunt binary.')"
+	@echo "$(call format,log,'Monitor the Magento log files. Pass no params to tail all files.')"
 	@echo "$(call format,magento,'Run the Magento CLI.')"
 	@echo "$(call format,mftf,'Run the Magento MFTF.')"
 	@echo "$(call format,mysql,'Run the MySQL CLI with database config from env/db.env.')"

+ 46 - 0
compose/bin/log

@@ -0,0 +1,46 @@
+#!/usr/bin/env bash
+
+CONTAINER_LOG_PATH="/var/www/html/var/log/";
+
+display_help() {
+  echo -e "Description:
+  Tail logs from the Magento var/log folder all and specific logs
+
+Usage:
+  bin/log <specific_log_files>
+
+Arguments:
+  specific_log_files  If specific_log_files are NOT provided, show all logs. Ex: bin/log system.log cache.log
+
+Options:
+  -h, --help          Display help message"
+}
+
+generate_logs_file_path() {
+  local container_log_path="$1"
+  shift  # This shifts the positional parameters to the left, so $2 becomes $1, $3 becomes $2, etc.
+  local log_files=("$@")
+  local log_file_paths=()
+
+  for file in "${log_files[@]}"; do
+    log_file_paths+=("$container_log_path$file")
+  done
+
+  echo "${log_file_paths[@]}"
+}
+
+get_all_logs_file_path() {
+  local logs_location="$1"
+
+  bin/docker-compose exec phpfpm ls -p "$logs_location" | grep -v '/$' | sed "s|^|$logs_location|"
+}
+
+if [[ $1 == "-h" || $1 == "--help" ]]; then
+  display_help
+elif [[ -z $1 ]]; then
+  mapfile -t all_logs_file_path < <(get_all_logs_file_path "$CONTAINER_LOG_PATH")
+  bin/docker-compose exec phpfpm tail -f "${all_logs_file_path[@]}"
+else
+  mapfile -t logs_file_path < <(generate_logs_file_path "$CONTAINER_LOG_PATH" "$@")
+  bin/docker-compose exec phpfpm tail -f "${logs_file_path[@]}"
+fi