Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bin/log command added #1060

Merged
merged 5 commits into from
Feb 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,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`
Expand Down
1 change: 1 addition & 0 deletions compose/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,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.')"
Expand Down
46 changes: 46 additions & 0 deletions compose/bin/log
Original file line number Diff line number Diff line change
@@ -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
Loading