Skip to content

Commit

Permalink
use a temporary log directory unless configured statically (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
David Coutadeur committed Oct 20, 2023
1 parent 08bb496 commit 96d5688
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
24 changes: 23 additions & 1 deletion bin/lsc
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,30 @@ fi

CFG_DIR="$LSC_HOME/etc"
LIB_DIR="$LSC_HOME/lib"
LOG_DIR="/tmp"

# Get logdir property from logback.xml
logdir=$( grep 'property[ ]\+name="logdir"' "${CFG_DIR}/logback.xml" | sed -e 's/^.*value="\([^"]*\)".*$/\1/' )
if [ "${logdir}" = "\${TMP_DIR}" ] || [ "${logdir}" = "\$TMP_DIR" ]; then
# Create temp directory
LOG_DIR="$( mktemp -d /tmp/lsc-$(date +%Y-%M-%d-%T).XXXXXXXXXX )"
echo "Using temporary log directory: ${LOG_DIR}"
# Pass LOG_DIR java system property with the temp directory value
JAVA_OPTS="${JAVA_OPTS} -DTMP_DIR=${LOG_DIR}"
elif [ "${logdir}" = "" ]; then
echo "WARN: empty log dir in logback.xml, using LOG_DIR=/tmp"
LOG_DIR="/tmp"
else
# Just use static value of logdir from logback.xml
LOG_DIR="${logdir}"
echo "Use static log directory: ${LOG_DIR}"
fi
LOG_FILE="$LOG_DIR/lsc.log"

# Create LOG_DIR in case LOG_DIR has been defined statically above
mkdir -p "$LOG_DIR"
if [ ! -d ${LOG_DIR} ]; then
echo "ERROR: LOG_DIR ${LOG_DIR} does not exist!"
fi

PARAMETERS="$*"

Expand Down Expand Up @@ -178,6 +198,8 @@ then
log "LSC finished running"
fi

echo "LSC has used LOG_DIR=\"${LOG_DIR}\""

#====================================================================
# Exit
#====================================================================
Expand Down
4 changes: 3 additions & 1 deletion etc/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

<configuration>

<property name="logdir" value="/tmp/lsc/log" />
<!-- logdir value can be set to a static directory path or to ${TMP_DIR} -->
<!-- ${TMP_DIR} is a temporary directory computed by bin/lsc and transmitted as a java system property -->
<property name="logdir" value="${TMP_DIR}" />

<!-- Standard output to console -->
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
Expand Down

0 comments on commit 96d5688

Please sign in to comment.