|
@@ -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
|