SOLR-9325: solr.log is now written to $SOLR_LOGS_DIR without changing log4j.properties

(cherry picked from commit 33db4de)
This commit is contained in:
Jan Høydahl 2016-10-14 23:19:09 +02:00
parent edde433594
commit bc5e06e34c
8 changed files with 59 additions and 12 deletions

View File

@ -138,6 +138,8 @@ Bug Fixes
* SOLR-9604: Pooled SSL connections were not being re-used (Alan Woodward, * SOLR-9604: Pooled SSL connections were not being re-used (Alan Woodward,
Mikhail Khludnev, hossman) Mikhail Khludnev, hossman)
* SOLR-9325: solr.log is now written to $SOLR_LOGS_DIR without changing log4j.properties (janhoy)
Optimizations Optimizations
---------------------- ----------------------

View File

@ -1568,7 +1568,7 @@ function launch_solr() {
fi fi
SOLR_START_OPTS=('-server' "${JAVA_MEM_OPTS[@]}" "${GC_TUNE[@]}" "${GC_LOG_OPTS[@]}" \ SOLR_START_OPTS=('-server' "${JAVA_MEM_OPTS[@]}" "${GC_TUNE[@]}" "${GC_LOG_OPTS[@]}" \
"${REMOTE_JMX_OPTS[@]}" "${CLOUD_MODE_OPTS[@]}" $SOLR_LOG_LEVEL_OPT \ "${REMOTE_JMX_OPTS[@]}" "${CLOUD_MODE_OPTS[@]}" $SOLR_LOG_LEVEL_OPT -Dsolr.log.dir="$SOLR_LOGS_DIR" \
"-Djetty.port=$SOLR_PORT" "-DSTOP.PORT=$stop_port" "-DSTOP.KEY=$STOP_KEY" \ "-Djetty.port=$SOLR_PORT" "-DSTOP.PORT=$stop_port" "-DSTOP.KEY=$STOP_KEY" \
"${SOLR_HOST_ARG[@]}" "-Duser.timezone=$SOLR_TIMEZONE" \ "${SOLR_HOST_ARG[@]}" "-Duser.timezone=$SOLR_TIMEZONE" \
"-Djetty.home=$SOLR_SERVER_DIR" "-Dsolr.solr.home=$SOLR_HOME" "-Dsolr.install.dir=$SOLR_TIP" \ "-Djetty.home=$SOLR_SERVER_DIR" "-Dsolr.solr.home=$SOLR_HOME" "-Dsolr.install.dir=$SOLR_TIP" \
@ -1578,7 +1578,21 @@ function launch_solr() {
IN_CLOUD_MODE=" in SolrCloud mode" IN_CLOUD_MODE=" in SolrCloud mode"
fi fi
mkdir -p "$SOLR_LOGS_DIR" mkdir -p "$SOLR_LOGS_DIR" 2>/dev/null
if [ $? -ne 0 ]; then
echo -e "\nERROR: Logs directory $SOLR_LOGS_DIR could not be created. Exiting"
exit 1
fi
if [ ! -w "$SOLR_LOGS_DIR" ]; then
echo -e "\nERROR: Logs directory $SOLR_LOGS_DIR is not writable. Exiting"
exit 1
fi
case "$SOLR_LOGS_DIR" in
contexts|etc|lib|modules|resources|scripts|solr|solr-webapp)
echo -e "\nERROR: Logs directory $SOLR_LOGS_DIR is invalid. Reserved for the system. Exiting"
exit 1
;;
esac
if [ "$run_in_foreground" == "true" ]; then if [ "$run_in_foreground" == "true" ]; then
exec "$JAVA" "${SOLR_START_OPTS[@]}" $SOLR_ADDL_ARGS -jar start.jar "${SOLR_JETTY_CONFIG[@]}" exec "$JAVA" "${SOLR_START_OPTS[@]}" $SOLR_ADDL_ARGS -jar start.jar "${SOLR_JETTY_CONFIG[@]}"

View File

@ -729,7 +729,13 @@ IF "%STOP_KEY%"=="" set STOP_KEY=solrrocks
@REM This is quite hacky, but examples rely on a different log4j.properties @REM This is quite hacky, but examples rely on a different log4j.properties
@REM so that we can write logs for examples to %SOLR_HOME%\..\logs @REM so that we can write logs for examples to %SOLR_HOME%\..\logs
set "SOLR_LOGS_DIR=%SOLR_SERVER_DIR%\logs" IF [%SOLR_LOGS_DIR%] == [] (
set "SOLR_LOGS_DIR=%SOLR_SERVER_DIR%\logs"
) ELSE (
set SOLR_LOGS_DIR=%SOLR_LOGS_DIR:"=%
)
set SOLR_LOGS_DIR_QUOTED="%SOLR_LOGS_DIR%"
set "EXAMPLE_DIR=%SOLR_TIP%\example" set "EXAMPLE_DIR=%SOLR_TIP%\example"
set TMP=!SOLR_HOME:%EXAMPLE_DIR%=! set TMP=!SOLR_HOME:%EXAMPLE_DIR%=!
IF NOT "%TMP%"=="%SOLR_HOME%" ( IF NOT "%TMP%"=="%SOLR_HOME%" (
@ -965,13 +971,26 @@ IF NOT "%SOLR_SSL_OPTS%"=="" (
set "START_OPTS=%START_OPTS% %SOLR_SSL_OPTS% !SSL_PORT_PROP!" set "START_OPTS=%START_OPTS% %SOLR_SSL_OPTS% !SSL_PORT_PROP!"
) )
IF NOT "%SOLR_LOG_LEVEL%"=="" set "START_OPTS=%START_OPTS% -Dsolr.log.level=%SOLR_LOG_LEVEL%" IF NOT "%SOLR_LOG_LEVEL%"=="" set "START_OPTS=%START_OPTS% -Dsolr.log.level=%SOLR_LOG_LEVEL%"
set "START_OPTS=%START_OPTS% -Dsolr.log.dir=%SOLR_LOGS_DIR_QUOTED%"
IF NOT DEFINED LOG4J_CONFIG set "LOG4J_CONFIG=file:%SOLR_SERVER_DIR%\resources\log4j.properties" IF NOT DEFINED LOG4J_CONFIG set "LOG4J_CONFIG=file:%SOLR_SERVER_DIR%\resources\log4j.properties"
cd /d "%SOLR_SERVER_DIR%" cd /d "%SOLR_SERVER_DIR%"
IF NOT EXIST "!SOLR_LOGS_DIR!" ( IF NOT EXIST "%SOLR_LOGS_DIR%" (
mkdir "!SOLR_LOGS_DIR!" mkdir "%SOLR_LOGS_DIR%"
)
copy /Y NUL "%SOLR_LOGS_DIR%\.writable" > NUL 2>&1 && set WRITEOK=1
IF DEFINED WRITEOK (
del "%SOLR_LOGS_DIR%\.writable"
) else (
echo "ERROR: Logs directory %SOLR_LOGS_DIR% is not writable or could not be created. Exiting"
GOTO :eof
)
echo " contexts etc lib modules resources scripts solr solr-webapp " > "%TEMP%\solr-pattern.txt"
findstr /i /C:" %SOLR_LOGS_DIR% " "%TEMP%\solr-pattern.txt" 1>nul
if %ERRORLEVEL% == 0 (
echo "ERROR: Logs directory %SOLR_LOGS_DIR% is invalid. Reserved for the system. Exiting"
GOTO :eof
) )
IF NOT EXIST "%SOLR_SERVER_DIR%\tmp" ( IF NOT EXIST "%SOLR_SERVER_DIR%\tmp" (
@ -988,13 +1007,13 @@ IF "%FG%"=="1" (
REM run solr in the foreground REM run solr in the foreground
title "Solr-%SOLR_PORT%" title "Solr-%SOLR_PORT%"
echo %SOLR_PORT%>"%SOLR_TIP%"\bin\solr-%SOLR_PORT%.port echo %SOLR_PORT%>"%SOLR_TIP%"\bin\solr-%SOLR_PORT%.port
"%JAVA%" %SERVEROPT% %SOLR_JAVA_MEM% %START_OPTS% %GCLOG_OPT%:"!SOLR_LOGS_DIR!"/solr_gc.log ^ "%JAVA%" %SERVEROPT% %SOLR_JAVA_MEM% %START_OPTS% %GCLOG_OPT%:"!SOLR_LOGS_DIR!/solr_gc.log" ^
-Dlog4j.configuration="%LOG4J_CONFIG%" -DSTOP.PORT=!STOP_PORT! -DSTOP.KEY=%STOP_KEY% ^ -Dlog4j.configuration="%LOG4J_CONFIG%" -DSTOP.PORT=!STOP_PORT! -DSTOP.KEY=%STOP_KEY% ^
-Djetty.port=%SOLR_PORT% -Dsolr.solr.home="%SOLR_HOME%" -Dsolr.install.dir="%SOLR_TIP%" ^ -Djetty.port=%SOLR_PORT% -Dsolr.solr.home="%SOLR_HOME%" -Dsolr.install.dir="%SOLR_TIP%" ^
-Djetty.home="%SOLR_SERVER_DIR%" -Djava.io.tmpdir="%SOLR_SERVER_DIR%\tmp" -jar start.jar "%SOLR_JETTY_CONFIG%" -Djetty.home="%SOLR_SERVER_DIR%" -Djava.io.tmpdir="%SOLR_SERVER_DIR%\tmp" -jar start.jar "%SOLR_JETTY_CONFIG%"
) ELSE ( ) ELSE (
START /B "Solr-%SOLR_PORT%" /D "%SOLR_SERVER_DIR%" "%JAVA%" %SERVEROPT% %SOLR_JAVA_MEM% %START_OPTS% ^ START /B "Solr-%SOLR_PORT%" /D "%SOLR_SERVER_DIR%" "%JAVA%" %SERVEROPT% %SOLR_JAVA_MEM% %START_OPTS% ^
%GCLOG_OPT%:"!SOLR_LOGS_DIR!"/solr_gc.log -Dlog4j.configuration="%LOG4J_CONFIG%" -DSTOP.PORT=!STOP_PORT! ^ %GCLOG_OPT%:"!SOLR_LOGS_DIR!/solr_gc.log" -Dlog4j.configuration="%LOG4J_CONFIG%" -DSTOP.PORT=!STOP_PORT! ^
-Dsolr.log.muteconsole ^ -Dsolr.log.muteconsole ^
-DSTOP.KEY=%STOP_KEY% -Djetty.port=%SOLR_PORT% -Dsolr.solr.home="%SOLR_HOME%" -Dsolr.install.dir="%SOLR_TIP%" ^ -DSTOP.KEY=%STOP_KEY% -Djetty.port=%SOLR_PORT% -Dsolr.solr.home="%SOLR_HOME%" -Dsolr.install.dir="%SOLR_TIP%" ^
-Djetty.home="%SOLR_SERVER_DIR%" -Djava.io.tmpdir="%SOLR_SERVER_DIR%\tmp" -jar start.jar ^ -Djetty.home="%SOLR_SERVER_DIR%" -Djava.io.tmpdir="%SOLR_SERVER_DIR%\tmp" -jar start.jar ^

View File

@ -31,6 +31,9 @@ REM Changes the logging level. Valid values: ALL, TRACE, DEBUG, INFO, WARN, ERRO
REM This is an alternative to changing the rootLogger in log4j.properties REM This is an alternative to changing the rootLogger in log4j.properties
REM set SOLR_LOG_LEVEL=INFO REM set SOLR_LOG_LEVEL=INFO
REM Location where Solr should write logs to. Absolute or relative to solr start dir
REM set SOLR_LOGS_DIR=logs
REM These GC settings have shown to work well for a number of common Solr workloads REM These GC settings have shown to work well for a number of common Solr workloads
set GC_TUNE=-XX:NewRatio=3 ^ set GC_TUNE=-XX:NewRatio=3 ^
-XX:SurvivorRatio=4 ^ -XX:SurvivorRatio=4 ^

View File

@ -96,9 +96,8 @@ SOLR_OPTS="$SOLR_OPTS -Xss256k"
# This is an alternative to changing the rootLogger in log4j.properties # This is an alternative to changing the rootLogger in log4j.properties
#SOLR_LOG_LEVEL=INFO #SOLR_LOG_LEVEL=INFO
# Location where Solr should write logs to; should agree with the file appender # Location where Solr should write logs to. Absolute or relative to solr start dir
# settings in server/resources/log4j.properties #SOLR_LOGS_DIR=logs
#SOLR_LOGS_DIR=
# Sets the port Solr binds to, default is 8983 # Sets the port Solr binds to, default is 8983
#SOLR_PORT=8983 #SOLR_PORT=8983

View File

@ -123,6 +123,7 @@ public class SolrDispatchFilter extends BaseSolrFilter {
{ {
log.trace("SolrDispatchFilter.init(): {}", this.getClass().getClassLoader()); log.trace("SolrDispatchFilter.init(): {}", this.getClass().getClassLoader());
StartupLoggingUtils.checkLogDir();
logWelcomeBanner(); logWelcomeBanner();
String muteConsole = System.getProperty(SOLR_LOG_MUTECONSOLE); String muteConsole = System.getProperty(SOLR_LOG_MUTECONSOLE);
if (muteConsole != null && !Arrays.asList("false","0","off","no").contains(muteConsole.toLowerCase(Locale.ROOT))) { if (muteConsole != null && !Arrays.asList("false","0","off","no").contains(muteConsole.toLowerCase(Locale.ROOT))) {

View File

@ -40,6 +40,15 @@ final class StartupLoggingUtils {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
private final static StaticLoggerBinder binder = StaticLoggerBinder.getSingleton(); private final static StaticLoggerBinder binder = StaticLoggerBinder.getSingleton();
/**
* Checks whether mandatory log dir is given
*/
static void checkLogDir() {
if (System.getProperty("solr.log.dir") == null) {
log.error("Missing Java Option solr.log.dir. Logging may be missing or incomplete.");
}
}
/** /**
* Disables all log4j ConsoleAppender's by modifying log4j configuration dynamically. * Disables all log4j ConsoleAppender's by modifying log4j configuration dynamically.
* Must only be used during early startup * Must only be used during early startup

View File

@ -1,6 +1,6 @@
# Default Solr log4j config # Default Solr log4j config
# rootLogger log level may be programmatically overridden by -Dsolr.log.level # rootLogger log level may be programmatically overridden by -Dsolr.log.level
solr.log=logs solr.log=${solr.log.dir}
log4j.rootLogger=INFO, file, CONSOLE log4j.rootLogger=INFO, file, CONSOLE
# Console appender will be programmatically disabled when Solr is started with option -Dsolr.log.muteconsole # Console appender will be programmatically disabled when Solr is started with option -Dsolr.log.muteconsole