Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use a temporary log directory unless configured statically (#95) #241

Merged
merged 1 commit into from
May 15, 2024
Merged
Show file tree
Hide file tree
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
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