From ad5cc986d86e9deff506c0451409f26fc8e86efe Mon Sep 17 00:00:00 2001 From: Dean Troyer Date: Wed, 10 Dec 2014 16:35:32 -0600 Subject: [PATCH] Rename screen logfiles This renames the log files in logs/screen that contain timestamps to put the timestamp after '.log' and '.log.summary' in the names. This will simplify devstack-gate's search for log files to copy to '*.log'. dstat.txt is also renamed to dstat.log Make LOGDIR and LOGFILE local bp:devstack-logging-and-service-names Change-Id: I02aba9ca82c117a1186dafc1d3c07aa04ecd1dde --- functions-common | 14 +++++++------- lib/dstat | 2 +- stack.sh | 19 +++++++++---------- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/functions-common b/functions-common index b0b262236d..23d59c7d98 100644 --- a/functions-common +++ b/functions-common @@ -1244,8 +1244,8 @@ function _run_process { exec 6>&- if [[ -n ${SCREEN_LOGDIR} ]]; then - exec 1>&${SCREEN_LOGDIR}/screen-${service}.${CURRENT_LOG_TIME}.log 2>&1 - ln -sf ${SCREEN_LOGDIR}/screen-${service}.${CURRENT_LOG_TIME}.log ${SCREEN_LOGDIR}/screen-${service}.log + exec 1>&${SCREEN_LOGDIR}/screen-${service}.log.${CURRENT_LOG_TIME} 2>&1 + ln -sf ${SCREEN_LOGDIR}/screen-${service}.log.${CURRENT_LOG_TIME} ${SCREEN_LOGDIR}/screen-${service}.log # TODO(dtroyer): Hack to get stdout from the Python interpreter for the logs. export PYTHONUNBUFFERED=1 @@ -1329,9 +1329,9 @@ function screen_process { screen -S $SCREEN_NAME -X screen -t $name if [[ -n ${SCREEN_LOGDIR} ]]; then - screen -S $SCREEN_NAME -p $name -X logfile ${SCREEN_LOGDIR}/screen-${name}.${CURRENT_LOG_TIME}.log + screen -S $SCREEN_NAME -p $name -X logfile ${SCREEN_LOGDIR}/screen-${name}.log.${CURRENT_LOG_TIME} screen -S $SCREEN_NAME -p $name -X log on - ln -sf ${SCREEN_LOGDIR}/screen-${name}.${CURRENT_LOG_TIME}.log ${SCREEN_LOGDIR}/screen-${name}.log + ln -sf ${SCREEN_LOGDIR}/screen-${name}.log.${CURRENT_LOG_TIME} ${SCREEN_LOGDIR}/screen-${name}.log fi # sleep to allow bash to be ready to be send the command - we are @@ -1377,7 +1377,7 @@ function screen_rc { echo "stuff \"$2$NL\"" >> $SCREENRC if [[ -n ${SCREEN_LOGDIR} ]]; then - echo "logfile ${SCREEN_LOGDIR}/screen-${1}.${CURRENT_LOG_TIME}.log" >>$SCREENRC + echo "logfile ${SCREEN_LOGDIR}/screen-${1}.log.${CURRENT_LOG_TIME}" >>$SCREENRC echo "log on" >>$SCREENRC fi fi @@ -1489,8 +1489,8 @@ function _old_run_process { exec 6>&- if [[ -n ${SCREEN_LOGDIR} ]]; then - exec 1>&${SCREEN_LOGDIR}/screen-${1}.${CURRENT_LOG_TIME}.log 2>&1 - ln -sf ${SCREEN_LOGDIR}/screen-${1}.${CURRENT_LOG_TIME}.log ${SCREEN_LOGDIR}/screen-${1}.log + exec 1>&${SCREEN_LOGDIR}/screen-${1}.log.${CURRENT_LOG_TIME} 2>&1 + ln -sf ${SCREEN_LOGDIR}/screen-${1}.log.${CURRENT_LOG_TIME} ${SCREEN_LOGDIR}/screen-${1}.log # TODO(dtroyer): Hack to get stdout from the Python interpreter for the logs. export PYTHONUNBUFFERED=1 diff --git a/lib/dstat b/lib/dstat index 73ca279fea..a17125fc92 100644 --- a/lib/dstat +++ b/lib/dstat @@ -20,7 +20,7 @@ set +o xtrace # Defaults # -------- # for DSTAT logging -DSTAT_FILE=${DSTAT_FILE:-"dstat.txt"} +DSTAT_FILE=${DSTAT_FILE:-"dstat.log"} # start_dstat() - Start running processes, including screen diff --git a/stack.sh b/stack.sh index 048e5d1a1e..f42e68ae08 100755 --- a/stack.sh +++ b/stack.sh @@ -370,15 +370,14 @@ if [[ -n "$LOGFILE" || -n "$SCREEN_LOGDIR" ]]; then fi if [[ -n "$LOGFILE" ]]; then - # First clean up old log files. Use the user-specified ``LOGFILE`` - # as the template to search for, appending '.*' to match the date - # we added on earlier runs. - LOGDIR=$(dirname "$LOGFILE") - LOGFILENAME=$(basename "$LOGFILE") - mkdir -p $LOGDIR - find $LOGDIR -maxdepth 1 -name $LOGFILENAME.\* -mtime +$LOGDAYS -exec rm {} \; + # Clean up old log files. Append '.*' to the user-specified + # ``LOGFILE`` to match the date in the search template. + local logfile_dir="${LOGFILE%/*}" # dirname + local logfile_name="${LOGFILE##*/}" # basename + mkdir -p $logfile_dir + find $logfile_dir -maxdepth 1 -name $logfile_name.\* -mtime +$LOGDAYS -exec rm {} \; LOGFILE=$LOGFILE.${CURRENT_LOG_TIME} - SUMFILE=$LOGFILE.${CURRENT_LOG_TIME}.summary + SUMFILE=$LOGFILE.summary.${CURRENT_LOG_TIME} # Redirect output according to config @@ -399,8 +398,8 @@ if [[ -n "$LOGFILE" ]]; then echo_summary "stack.sh log $LOGFILE" # Specified logfile name always links to the most recent log - ln -sf $LOGFILE $LOGDIR/$LOGFILENAME - ln -sf $SUMFILE $LOGDIR/$LOGFILENAME.summary + ln -sf $LOGFILE $logfile_dir/$logfile_name + ln -sf $SUMFILE $logfile_dir/$logfile_name.summary else # Set up output redirection without log files # Set fd 3 to a copy of stdout. So we can set fd 1 without losing