Hi Janhoy,

the commit breaks forbidden-apis checks, because direct usage of Log4J instead 
of Slf4J warppers is not wanted for application code. I think this one is 
special, so I'd move the silencer stuff to a private method that’s called from 
init(). This private method could be @SuppressForbidden. Please don't make the 
whole class or init() suppressed.

I'd still add this in a huge try-catch block, so users not using log4j don't 
break. We have similar stuff at other places, too. I think we also have a 
separate class to initialize the logging system, so the DispatchFilter is the 
wrong place for this to live: CheckLoggingConfiguration.java

Uwe

-----
Uwe Schindler
H.-H.-Meier-Allee 63, D-28213 Bremen
http://www.thetaphi.de
eMail: u...@thetaphi.de

> -----Original Message-----
> From: jan...@apache.org [mailto:jan...@apache.org]
> Sent: Thursday, September 22, 2016 1:21 AM
> To: comm...@lucene.apache.org
> Subject: lucene-solr:master: SOLR-8186: Solr start scripts, only log to 
> console
> when running in foreground
> 
> Repository: lucene-solr
> Updated Branches:
>   refs/heads/master 7561461f7 -> 2ef34e9e2
> 
> 
> SOLR-8186: Solr start scripts, only log to console when running in foreground
> 
> 
> Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
> Commit: http://git-wip-us.apache.org/repos/asf/lucene-
> solr/commit/2ef34e9e
> Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/2ef34e9e
> Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/2ef34e9e
> 
> Branch: refs/heads/master
> Commit: 2ef34e9e24ac2c0bd72de54c3edda9ba3aa43728
> Parents: 7561461
> Author: Jan HC8ydahl <jan...@apache.org>
> Authored: Thu Sep 22 01:18:27 2016 +0200
> Committer: Jan HC8ydahl <jan...@apache.org>
> Committed: Thu Sep 22 01:18:27 2016 +0200
> 
> ----------------------------------------------------------------------
>  solr/CHANGES.txt                                 |  3 +++
>  solr/bin/solr                                    |  2 +-
>  solr/bin/solr.cmd                                | 17 ++++++++++++-----
>  .../java/org/apache/solr/core/CoreContainer.java |  4 +++-
>  .../apache/solr/servlet/SolrDispatchFilter.java  | 19 +++++++++++++++++++
>  solr/server/resources/log4j.properties           |  4 ++--
>  solr/webapp/web/WEB-INF/web.xml                  | 17 +++++++++++++++++
>  7 files changed, 57 insertions(+), 9 deletions(-)
> ----------------------------------------------------------------------
> 
> 
> http://git-wip-us.apache.org/repos/asf/lucene-
> solr/blob/2ef34e9e/solr/CHANGES.txt
> ----------------------------------------------------------------------
> diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
> index 0119917..391381a 100644
> --- a/solr/CHANGES.txt
> +++ b/solr/CHANGES.txt
> @@ -87,6 +87,9 @@ New Features
> 
>  * SOLR-9319: DELETEREPLICA can accept a 'count' and remove appropriate
> replicas (Nitin Sharma, noble)
> 
> +* SOLR-8186: Reduce logging to logs/solr-<port>-console.log when not
> running in foreground mode
> +  Show timestamp also in foreground log. Also removes some logging noise.
> (janhoy)
> +
>  Bug Fixes
>  ----------------------
> 
> 
> http://git-wip-us.apache.org/repos/asf/lucene-
> solr/blob/2ef34e9e/solr/bin/solr
> ----------------------------------------------------------------------
> diff --git a/solr/bin/solr b/solr/bin/solr
> index e2a665d..d3c6530 100755
> --- a/solr/bin/solr
> +++ b/solr/bin/solr
> @@ -1547,7 +1547,7 @@ function launch_solr() {
>      exec "$JAVA" "${SOLR_START_OPTS[@]}" $SOLR_ADDL_ARGS -jar start.jar
> "${SOLR_JETTY_CONFIG[@]}"
>    else
>      # run Solr in the background
> -    nohup "$JAVA" "${SOLR_START_OPTS[@]}" $SOLR_ADDL_ARGS \
> +    nohup "$JAVA" "${SOLR_START_OPTS[@]}" $SOLR_ADDL_ARGS -
> Dsolr.log.muteconsole \
>       "-XX:OnOutOfMemoryError=$SOLR_TIP/bin/oom_solr.sh
> $SOLR_PORT $SOLR_LOGS_DIR" \
>          -jar start.jar "${SOLR_JETTY_CONFIG[@]}" \
>       1>"$SOLR_LOGS_DIR/solr-$SOLR_PORT-console.log" 2>&1 & echo $!
> > "$SOLR_PID_DIR/solr-$SOLR_PORT.pid"
> 
> http://git-wip-us.apache.org/repos/asf/lucene-
> solr/blob/2ef34e9e/solr/bin/solr.cmd
> ----------------------------------------------------------------------
> diff --git a/solr/bin/solr.cmd b/solr/bin/solr.cmd
> index e9c8f84..2e6e6a9 100644
> --- a/solr/bin/solr.cmd
> +++ b/solr/bin/solr.cmd
> @@ -968,15 +968,22 @@ IF "%FG%"=="1" (
>    REM run solr in the foreground
>    title "Solr-%SOLR_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 -
> 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.home="%SOLR_SERVER_DIR%" -
> Djava.io.tmpdir="%SOLR_SERVER_DIR%\tmp" -jar start.jar
> "%SOLR_JETTY_CONFIG%"
> +  "%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% ^
> +    -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%"
>  ) ELSE (
> -  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! -
> 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
> "%SOLR_JETTY_CONFIG%" > "!SOLR_LOGS_DIR!\solr-%SOLR_PORT%-
> console.log"
> +  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! ^
> +    -Dsolr.log.muteconsole ^
> +    -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 ^
> +    "%SOLR_JETTY_CONFIG%" > "!SOLR_LOGS_DIR!\solr-%SOLR_PORT%-
> console.log"
>    echo %SOLR_PORT%>"%SOLR_TIP%"\bin\solr-%SOLR_PORT%.port
> 
>    REM now wait to see Solr come online ...
> -  "%JAVA%" %SOLR_SSL_OPTS% %SOLR_ZK_CREDS_AND_ACLS% -
> Dsolr.install.dir="%SOLR_TIP%" -
> Dlog4j.configuration="file:%DEFAULT_SERVER_DIR%\scripts\cloud-
> scripts\log4j.properties" ^
> +  "%JAVA%" %SOLR_SSL_OPTS% %SOLR_ZK_CREDS_AND_ACLS% -
> Dsolr.install.dir="%SOLR_TIP%" ^
> +    -Dlog4j.configuration="file:%DEFAULT_SERVER_DIR%\scripts\cloud-
> scripts\log4j.properties" ^
>      -classpath "%DEFAULT_SERVER_DIR%\solr-webapp\webapp\WEB-
> INF\lib\*;%DEFAULT_SERVER_DIR%\lib\ext\*" ^
>      org.apache.solr.util.SolrCLI status -maxWaitSecs 30 -solr
> !SOLR_URL_SCHEME!://%SOLR_TOOL_HOST%:%SOLR_PORT%/solr
>  )
> 
> http://git-wip-us.apache.org/repos/asf/lucene-
> solr/blob/2ef34e9e/solr/core/src/java/org/apache/solr/core/CoreContainer.
> java
> ----------------------------------------------------------------------
> diff --git a/solr/core/src/java/org/apache/solr/core/CoreContainer.java
> b/solr/core/src/java/org/apache/solr/core/CoreContainer.java
> index 0ccf2de..2a7e516 100644
> --- a/solr/core/src/java/org/apache/solr/core/CoreContainer.java
> +++ b/solr/core/src/java/org/apache/solr/core/CoreContainer.java
> @@ -441,7 +441,9 @@ public class CoreContainer {
>          loader.addToClassLoader(SolrResourceLoader.getURLs(libPath));
>          loader.reloadLuceneSPI();
>        } catch (IOException e) {
> -        log.warn("Couldn't add files from {} to classpath: {}", libPath,
> e.getMessage());
> +        if (!libDir.equals("lib")) { // Don't complain if default "lib" dir 
> does not
> exist
> +          log.warn("Couldn't add files from {} to classpath: {}", libPath,
> e.getMessage());
> +        }
>        }
>      }
> 
> 
> http://git-wip-us.apache.org/repos/asf/lucene-
> solr/blob/2ef34e9e/solr/core/src/java/org/apache/solr/servlet/SolrDispatch
> Filter.java
> ----------------------------------------------------------------------
> diff --git 
> a/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java
> b/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java
> index 17cd6b5..bbcd615 100644
> --- a/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java
> +++ b/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java
> @@ -36,6 +36,9 @@ import java.lang.invoke.MethodHandles;
>  import java.nio.file.Path;
>  import java.nio.file.Paths;
>  import java.util.ArrayList;
> +import java.util.Arrays;
> +import java.util.Enumeration;
> +import java.util.Locale;
>  import java.util.Properties;
>  import java.util.concurrent.atomic.AtomicBoolean;
>  import java.util.concurrent.atomic.AtomicReference;
> @@ -46,6 +49,9 @@ import
> org.apache.commons.io.input.CloseShieldInputStream;
>  import org.apache.commons.io.output.CloseShieldOutputStream;
>  import org.apache.commons.lang.StringUtils;
>  import org.apache.http.client.HttpClient;
> +import org.apache.log4j.Appender;
> +import org.apache.log4j.ConsoleAppender;
> +import org.apache.log4j.LogManager;
>  import org.apache.solr.common.SolrException;
>  import org.apache.solr.common.SolrException.ErrorCode;
>  import org.apache.solr.common.cloud.SolrZkClient;
> @@ -110,9 +116,22 @@ public class SolrDispatchFilter extends BaseSolrFilter
> {
> 
>    public static final String SOLRHOME_ATTRIBUTE = "solr.solr.home";
> 
> +  public static final String SOLR_LOG_MUTECONSOLE =
> "solr.log.muteconsole";
> +
>    @Override
>    public void init(FilterConfig config) throws ServletException
>    {
> +    String muteConsole = System.getProperty(SOLR_LOG_MUTECONSOLE);
> +    if (muteConsole != null &&
> !Arrays.asList("false","0","off","no").contains(muteConsole.toLowerCase(Loc
> ale.ROOT))) {
> +      Enumeration appenders =
> LogManager.getRootLogger().getAllAppenders();
> +      while (appenders.hasMoreElements()) {
> +        Appender appender = (Appender) appenders.nextElement();
> +        if (appender instanceof ConsoleAppender) {
> +          log.info("Property solr.log.muteconsole given. Muting
> ConsoleAppender named " + appender.getName());
> +          LogManager.getRootLogger().removeAppender(appender);
> +        }
> +      }
> +    }
>      log.info("SolrDispatchFilter.init(): {}", 
> this.getClass().getClassLoader());
> 
>      String exclude = config.getInitParameter("excludePatterns");
> 
> http://git-wip-us.apache.org/repos/asf/lucene-
> solr/blob/2ef34e9e/solr/server/resources/log4j.properties
> ----------------------------------------------------------------------
> diff --git a/solr/server/resources/log4j.properties
> b/solr/server/resources/log4j.properties
> index d5ebcd1..672af4c 100644
> --- a/solr/server/resources/log4j.properties
> +++ b/solr/server/resources/log4j.properties
> @@ -2,10 +2,10 @@
>  solr.log=logs
>  log4j.rootLogger=INFO, file, CONSOLE
> 
> +# Console appender will be programmatically disabled when Solr is started
> with option -Dsolr.log.muteconsole
>  log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
> -
>  log4j.appender.CONSOLE.layout=org.apache.log4j.EnhancedPatternLayout
> -log4j.appender.CONSOLE.layout.ConversionPattern=%-4r %-5p (%t)
> [%X{collection} %X{shard} %X{replica} %X{core}] %c{1.} %m%n
> +log4j.appender.CONSOLE.layout.ConversionPattern=%d{yyyy-MM-dd
> HH:mm:ss.SSS} %-5p (%t) [%X{collection} %X{shard} %X{replica} %X{core}]
> %c{1.} %m%n
> 
>  #- size rotation with log cleanup.
>  log4j.appender.file=org.apache.log4j.RollingFileAppender
> 
> http://git-wip-us.apache.org/repos/asf/lucene-
> solr/blob/2ef34e9e/solr/webapp/web/WEB-INF/web.xml
> ----------------------------------------------------------------------
> diff --git a/solr/webapp/web/WEB-INF/web.xml b/solr/webapp/web/WEB-
> INF/web.xml
> index 24a27ae..5278ae5 100644
> --- a/solr/webapp/web/WEB-INF/web.xml
> +++ b/solr/webapp/web/WEB-INF/web.xml
> @@ -164,4 +164,21 @@
>      <welcome-file>index.html</welcome-file>
>    </welcome-file-list>
> 
> +  <!-- Get rid of error message -->
> +  <security-constraint>
> +    <web-resource-collection>
> +      <web-resource-name>Disable TRACE</web-resource-name>
> +      <url-pattern>/</url-pattern>
> +      <http-method>TRACE</http-method>
> +    </web-resource-collection>
> +    <auth-constraint/>
> +  </security-constraint>
> +  <security-constraint>
> +    <web-resource-collection>
> +      <web-resource-name>Enable everything but TRACE</web-resource-
> name>
> +      <url-pattern>/</url-pattern>
> +      <http-method-omission>TRACE</http-method-omission>
> +    </web-resource-collection>
> +  </security-constraint>
> +
>  </web-app>


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@lucene.apache.org
For additional commands, e-mail: dev-h...@lucene.apache.org

Reply via email to