Skip to content
Open
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
14 changes: 9 additions & 5 deletions tools/log.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@ CASENAME="$(pwd | xargs basename)"
LOGFILE="$CASENAME.log"
export LOGFILE

STARTDATE="$(date --rfc-email)"
rfc_email_date() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rfc_email_date directly refers to the implementation options (--rfc-email), which is the non-portable part. A more general name would be better.

date --rfc-email 2>/dev/null || date '+%a, %d %b %Y %H:%M:%S %z'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the 2>/dev/null? If there is an error, I would rather see it than get the script to fail silently.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If --rfc-email is not portable, why provide an explicit format as fallback, instead of making the explicit format the only option? That should work on every system.

}

STARTDATE="$(rfc_email_date)"
STARTTIME="$(date +%s)"
echo "Started on: $STARTDATE" | tee "$CASENAME.log" 2>&1

close_log() {
echo "Started on: $STARTDATE" | tee --append "$LOGFILE" 2>&1
ENDDATE="$(date --rfc-email)"
echo "Started on: $STARTDATE" | tee -a "$LOGFILE" 2>&1
ENDDATE="$(rfc_email_date)"
ENDTIME="$(date +%s)"
echo "Finished on: $ENDDATE" | tee --append "$LOGFILE" 2>&1
echo "Duration: $((ENDTIME-STARTTIME)) seconds (wall-clock time, including time waiting for participants)" | tee --append "$LOGFILE" 2>&1
echo "Finished on: $ENDDATE" | tee -a "$LOGFILE" 2>&1
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's wrong with --apend? I used the verbose option for readability.

I don't have a macOS system to test on, but this page, for example, suggests that both are valid.

echo "Duration: $((ENDTIME-STARTTIME)) seconds (wall-clock time, including time waiting for participants)" | tee -a "$LOGFILE" 2>&1
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you post some example output from this script, to see the format and the computed time?

}
Loading