svn commit: r1004 - logback/trunk/logback-access/src/main/java/ch/qos/logback/access/jetty

Author: ceki Date: Sat Nov 25 14:50:17 2006 New Revision: 1004 Modified: logback/trunk/logback-access/src/main/java/ch/qos/logback/access/jetty/RequestLogImpl.java Log: - don't crash the server in case JoranConfiguration throws an exception Modified: logback/trunk/logback-access/src/main/java/ch/qos/logback/access/jetty/RequestLogImpl.java ============================================================================== --- logback/trunk/logback-access/src/main/java/ch/qos/logback/access/jetty/RequestLogImpl.java (original) +++ logback/trunk/logback-access/src/main/java/ch/qos/logback/access/jetty/RequestLogImpl.java Sat Nov 25 14:50:17 2006 @@ -22,7 +22,6 @@ import ch.qos.logback.core.spi.FilterReply; import ch.qos.logback.core.status.ErrorStatus; import ch.qos.logback.core.status.InfoStatus; -import ch.qos.logback.core.status.Status; import ch.qos.logback.core.status.WarnStatus; import ch.qos.logback.core.util.StatusPrinter; @@ -37,11 +36,11 @@ * be added to the jetty configuration file, namely <em>etc/jetty.xml</em>: * * <pre> - * <Ref id="requestLog"> - * <Set name="requestLog"> - * <New id="requestLogImpl" class="ch.qos.logback.access.jetty.RequestLogImpl"></New> - * </Set> - * </Ref> + * <Ref id="requestLog"> + * <Set name="requestLog"> + * <New id="requestLogImpl" class="ch.qos.logback.access.jetty.RequestLogImpl"></New> + * </Set> + * </Ref> * </pre> * * By default, RequestLogImpl looks for a logback configuration file called @@ -56,45 +55,45 @@ * logback-access.xml file. * * <pre> - * <Ref id="requestLog"> - * <Set name="requestLog"> - * <New id="requestLogImpl" class="ch.qos.logback.access.jetty.RequestLogImpl"></New> - * <Set name="fileName">path/to/logback.xml</Set> - * </Set> - * </Ref> + * <Ref id="requestLog"> + * <Set name="requestLog"> + * <New id="requestLogImpl" class="ch.qos.logback.access.jetty.RequestLogImpl"></New> + * <Set name="fileName">path/to/logback.xml</Set> + * </Set> + * </Ref> * </pre> * * <p> * Here is a sample logback-access.xml file that can be used right away: * * <pre> - * <configuration> - * <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> - * <layout class="ch.qos.logback.access.PatternLayout"> - * <param name="Pattern" value="%date %server %remoteIP %clientHost %user %requestURL" /> - * </layout> - * </appender> - * - * <appender-ref ref="STDOUT" /> - * </configuration> + * <configuration> + * <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> + * <layout class="ch.qos.logback.access.PatternLayout"> + * <param name="Pattern" value="%date %server %remoteIP %clientHost %user %requestURL" /> + * </layout> + * </appender> + * + * <appender-ref ref="STDOUT" /> + * </configuration> * </pre> * * <p> * Another configuration file, using SMTPAppender, could be: * * <pre> - * <configuration> - * <appender name="SMTP" class="ch.qos.logback.access.net.SMTPAppender"> - * <layout class="ch.qos.logback.access.PatternLayout"> - * <param name="pattern" value="%remoteIP [%date] %requestURL %statusCode %bytesSent" /> - * </layout> - * <param name="From" value="sender@domaine.org" /> - * <param name="SMTPHost" value="mail.domain.org" /> - * <param name="Subject" value="Last Event: %statusCode %requestURL" /> - * <param name="To" value="server_admin@domain.org" /> - * </appender> - * <appender-ref ref="SMTP" /> - * </configuration> + * <configuration> + * <appender name="SMTP" class="ch.qos.logback.access.net.SMTPAppender"> + * <layout class="ch.qos.logback.access.PatternLayout"> + * <param name="pattern" value="%remoteIP [%date] %requestURL %statusCode %bytesSent" /> + * </layout> + * <param name="From" value="sender@domaine.org" /> + * <param name="SMTPHost" value="mail.domain.org" /> + * <param name="Subject" value="Last Event: %statusCode %requestURL" /> + * <param name="To" value="server_admin@domain.org" /> + * </appender> + * <appender-ref ref="SMTP" /> + * </configuration> * </pre> * * <p> @@ -129,7 +128,7 @@ jettyResponse); AccessEvent accessEvent = new AccessEvent(jettyRequest, jettyResponse, adapter); - + if (getFilterChainDecision(accessEvent) == FilterReply.DENY) { return; } @@ -137,7 +136,7 @@ aai.appendLoopOnAppenders(accessEvent); } - public void start() { + public void start() { if (filename == null) { String jettyHomeProperty = System.getProperty("jetty.home"); @@ -148,31 +147,31 @@ + "]", this)); } - File configFile = new File(filename); - if (configFile.exists()) { - JoranConfigurator jc = new JoranConfigurator(); - jc.setContext(this); - try { + try { + File configFile = new File(filename); + if (configFile.exists()) { + JoranConfigurator jc = new JoranConfigurator(); + jc.setContext(this); jc.doConfigure(filename); - } catch (JoranException e) { - e.printStackTrace(System.out); + + } else { + getStatusManager().add( + new ErrorStatus("[" + filename + "] does not exist", this)); + } + + if (getName() == null) { + setName("LogbackRequestLog"); } - - } else { + RequestLogRegistry.register(this); getStatusManager().add( - new ErrorStatus("[" + filename + "] does not exist", this)); - } - - if (getName() == null) { - setName("LogbackRequestLog"); - } - RequestLogRegistry.register(this); - getStatusManager().add( - new InfoStatus("RequestLog added to RequestLogMapper with name: " + getName(), this)); + new InfoStatus("RequestLog added to RequestLogMapper with name: " + + getName(), this)); - if(getStatusManager().getLevel() != Status.INFO) { - StatusPrinter.print(getStatusManager()); + } catch (JoranException e) { + // errors have been registered as status messages } + + StatusPrinter.print(getStatusManager()); } public void stop() throws Exception {
participants (1)
-
noreply.ceki@qos.ch