Skip to content

Commit f1be0fc

Browse files
committed
Much faster ts() function on BASH versions which support it
1 parent 2f21e12 commit f1be0fc

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

src/psij/launchers/scripts/launcher_lib.sh

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,23 @@ if [ "$_PSI_J_LOG_FILE" == "" ]; then
3434
_PSI_J_LOG_FILE="/dev/null"
3535
fi
3636

37-
ts() {
38-
while read LINE; do
39-
TZ=UTC TS=$(date '+%Y-%m-%d %H:%M:%S')
40-
echo "$TS $_PSI_J_JOB_ID $LINE"
41-
done
42-
}
37+
if [ "${BASH_VERSINFO[0]}" -gt 4 ] || { [ "${BASH_VERSINFO[0]}" -eq 4 ] && [ "${BASH_VERSINFO[1]}" -ge 2 ]; }; then
38+
ts() {
39+
local TZ=UTC
40+
while read LINE; do
41+
printf -v TS '%(%Y-%m-%d %H:%M:%S)T' -1
42+
echo "$TS $_PSI_J_JOB_ID $LINE"
43+
done
44+
}
45+
else
46+
ts() {
47+
local TZ=UTC
48+
while read LINE; do
49+
TS=$(date '+%Y-%m-%d %H:%M:%S')
50+
echo "$TS $_PSI_J_JOB_ID $LINE"
51+
done
52+
}
53+
fi
4354

4455
log() {
4556
echo "$@" >&3

0 commit comments

Comments
 (0)