Skip to content

Commit defde77

Browse files
authored
Merge pull request #1060 from bbakalov/bin-log-command
2 parents 6e93776 + c3e761e commit defde77

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ It is recommended to keep your root docker config files in one repository, and y
290290
- `bin/fixperms`: This will fix filesystem permissions within the container.
291291
- `bin/grunt`: Run the grunt binary. Ex. `bin/grunt exec`
292292
- `bin/install-php-extensions`: Install PHP extension in the container. Ex. `bin/install-php-extensions sourceguardian`
293+
- `bin/log`: Monitor the Magento log files. Pass no params to tail all files. Ex. `bin/log debug.log`
293294
- `bin/magento`: Run the Magento CLI. Ex: `bin/magento cache:flush`
294295
- `bin/mftf`: Run the Magento MFTF. Ex: `bin/mftf build:project`
295296
- `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`

compose/Makefile

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

compose/bin/log

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

0 commit comments

Comments
 (0)