-
Notifications
You must be signed in to change notification settings - Fork 0
/
ulog
executable file
·30 lines (26 loc) · 876 Bytes
/
ulog
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/bin/zsh
# ~/bin/ulogs
# Find the project root directory by looking for .git
function find_project_root() {
local dir=$PWD
while [[ $dir != "/" ]]; do
if [[ -d $dir/.git ]]; then
echo $dir
return 0
fi
dir=${dir:h} # zsh way to get parent directory
done
echo $PWD # Return current directory if .git is not found
}
# Ensure the log file and directory exist
log_file=~/work/unified.log
mkdir -p ${log_file:h} # Create work directory if it doesn't exist
touch $log_file # Create log file if it doesn't exist
# Get service name from project root directory
project_root=$(find_project_root)
service=${project_root:t} # zsh way to get basename
timestamp=$(date '+%Y-%m-%d %H:%M:%S')
# Process all arguments as messages
for message in $@; do
echo "$timestamp [$service] $message" >> $log_file
done