Adding System.Property support to RollingFileAppender
* Adding ability to specify system properties like "${user.dir}" to the RollingFileAppender.filename configuration options. * Adding -config artifact creation. git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@851 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
parent
1148817866
commit
d4f7e008e9
|
@ -28,6 +28,27 @@
|
||||||
<artifactId>jetty-centralized-logging</artifactId>
|
<artifactId>jetty-centralized-logging</artifactId>
|
||||||
<name>Jetty :: Centralized Logging</name>
|
<name>Jetty :: Centralized Logging</name>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-assembly-plugin</artifactId>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>single</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<descriptors>
|
||||||
|
<descriptor>config.xml</descriptor>
|
||||||
|
</descriptors>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.eclipse.jetty</groupId>
|
<groupId>org.eclipse.jetty</groupId>
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
root.level=INFO
|
||||||
|
root.appenders=roll
|
||||||
|
|
||||||
|
appender.roll.class=org.eclipse.jetty.logging.impl.RollingFileAppender
|
||||||
|
appender.roll.filename=${jetty.home}/logs/central.log
|
||||||
|
appender.roll.append=true
|
||||||
|
appender.roll.retainDays=120
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
|
||||||
|
|
||||||
|
<!-- =============================================================== -->
|
||||||
|
<!-- Enable Centralized Logging in the Jetty Server -->
|
||||||
|
<!-- =============================================================== -->
|
||||||
|
|
||||||
|
<Configure id="Server" class="org.eclipse.jetty.server.Server">
|
||||||
|
<Call name="addBean">
|
||||||
|
<Arg>
|
||||||
|
<New class="org.eclipse.jetty.logging.CentralizedLogging">
|
||||||
|
<Set name="server"><Ref id="Server" /></Set>
|
||||||
|
<Set name="configurationFilename"><SystemProperty name="jetty.home" default="."/>/etc/centralized-logging/logging.properties</Set>
|
||||||
|
</New>
|
||||||
|
</Arg>
|
||||||
|
</Call>
|
||||||
|
</Configure>
|
|
@ -0,0 +1,45 @@
|
||||||
|
// ========================================================================
|
||||||
|
// Copyright (c) Webtide LLC
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
// All rights reserved. This program and the accompanying materials
|
||||||
|
// are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
// and Apache License v2.0 which accompanies this distribution.
|
||||||
|
//
|
||||||
|
// The Eclipse Public License is available at
|
||||||
|
// http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
//
|
||||||
|
// The Apache License v2.0 is available at
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0.txt
|
||||||
|
//
|
||||||
|
// You may elect to redistribute this code under either of these licenses.
|
||||||
|
// ========================================================================
|
||||||
|
package org.eclipse.jetty.logging;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Basic System Property string expansion "${user.home}"
|
||||||
|
*/
|
||||||
|
public class PropertyExpansion
|
||||||
|
{
|
||||||
|
public static String expand(String s)
|
||||||
|
{
|
||||||
|
int i1 = 0;
|
||||||
|
int i2 = 0;
|
||||||
|
|
||||||
|
i1 = 0;
|
||||||
|
i2 = 0;
|
||||||
|
while (s != null)
|
||||||
|
{
|
||||||
|
i1 = s.indexOf("${",i2);
|
||||||
|
if (i1 < 0)
|
||||||
|
break;
|
||||||
|
i2 = s.indexOf("}",i1 + 2);
|
||||||
|
if (i2 < 0)
|
||||||
|
break;
|
||||||
|
String name = s.substring(i1 + 2,i2);
|
||||||
|
String property = System.getProperty(name,"${" + name + "}");
|
||||||
|
s = s.substring(0,i1) + property + s.substring(i2 + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
}
|
|
@ -15,10 +15,13 @@
|
||||||
// ========================================================================
|
// ========================================================================
|
||||||
package org.eclipse.jetty.logging.impl;
|
package org.eclipse.jetty.logging.impl;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
|
|
||||||
|
import org.eclipse.jetty.logging.PropertyExpansion;
|
||||||
import org.eclipse.jetty.util.RolloverFileOutputStream;
|
import org.eclipse.jetty.util.RolloverFileOutputStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -28,6 +31,7 @@ public class RollingFileAppender implements Appender
|
||||||
{
|
{
|
||||||
private RolloverFileOutputStream out;
|
private RolloverFileOutputStream out;
|
||||||
private String filename;
|
private String filename;
|
||||||
|
private File file;
|
||||||
private boolean append = true;
|
private boolean append = true;
|
||||||
private int retainDays = 31;
|
private int retainDays = 31;
|
||||||
private TimeZone zone = TimeZone.getDefault();
|
private TimeZone zone = TimeZone.getDefault();
|
||||||
|
@ -98,9 +102,27 @@ public class RollingFileAppender implements Appender
|
||||||
return append;
|
return append;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public File getFile()
|
||||||
|
{
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
|
||||||
public void open() throws IOException
|
public void open() throws IOException
|
||||||
{
|
{
|
||||||
out = new RolloverFileOutputStream(filename,append,retainDays,zone,dateFormat,backupFormat);
|
file = new File(PropertyExpansion.expand(filename));
|
||||||
|
|
||||||
|
File logDir = file.getParentFile();
|
||||||
|
if (!logDir.exists())
|
||||||
|
{
|
||||||
|
throw new FileNotFoundException("Logging directory does not exist: " + logDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!logDir.isDirectory())
|
||||||
|
{
|
||||||
|
throw new FileNotFoundException("Logging path exist, but is not a directory: " + logDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
out = new RolloverFileOutputStream(file.getAbsolutePath(),append,retainDays,zone,dateFormat,backupFormat);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAppend(boolean append)
|
public void setAppend(boolean append)
|
||||||
|
|
|
@ -127,12 +127,13 @@ public class ConfiguredLoggerTest extends TestCase
|
||||||
|
|
||||||
File testLoggingDir = new File(MavenTestingUtils.getTargetTestingDir(this),"logs");
|
File testLoggingDir = new File(MavenTestingUtils.getTargetTestingDir(this),"logs");
|
||||||
testLoggingDir.mkdirs();
|
testLoggingDir.mkdirs();
|
||||||
File logFile = new File(testLoggingDir,"rolling.log");
|
|
||||||
|
System.setProperty("test.dir",testLoggingDir.getAbsolutePath());
|
||||||
|
|
||||||
props.setProperty("root.level","DEBUG");
|
props.setProperty("root.level","DEBUG");
|
||||||
props.setProperty("root.appenders","roll");
|
props.setProperty("root.appenders","roll");
|
||||||
props.setProperty("appender.roll.class",RollingFileAppender.class.getName());
|
props.setProperty("appender.roll.class",RollingFileAppender.class.getName());
|
||||||
props.setProperty("appender.roll.filename",logFile.getAbsolutePath());
|
props.setProperty("appender.roll.filename","${test.dir}/rolling.log");
|
||||||
props.setProperty("appender.roll.append","true");
|
props.setProperty("appender.roll.append","true");
|
||||||
props.setProperty("appender.roll.retainDays","120");
|
props.setProperty("appender.roll.retainDays","120");
|
||||||
props.setProperty("appender.roll.zone","GMT");
|
props.setProperty("appender.roll.zone","GMT");
|
||||||
|
@ -144,8 +145,10 @@ public class ConfiguredLoggerTest extends TestCase
|
||||||
assertSeverityLevel(root,Severity.DEBUG);
|
assertSeverityLevel(root,Severity.DEBUG);
|
||||||
assertAppenders(root,RollingFileAppender.class);
|
assertAppenders(root,RollingFileAppender.class);
|
||||||
|
|
||||||
|
File logFile = new File(testLoggingDir,"rolling.log");
|
||||||
|
|
||||||
RollingFileAppender actualAppender = (RollingFileAppender)root.getAppenders().get(0);
|
RollingFileAppender actualAppender = (RollingFileAppender)root.getAppenders().get(0);
|
||||||
assertEquals("RollingFileAppender.filename",logFile.getAbsolutePath(),actualAppender.getFilename());
|
assertEquals("RollingFileAppender.filename",logFile.getAbsolutePath(),actualAppender.getFile().getAbsolutePath());
|
||||||
assertEquals("RollingFileAppender.append",true,actualAppender.isAppend());
|
assertEquals("RollingFileAppender.append",true,actualAppender.isAppend());
|
||||||
assertEquals("RollingFileAppender.retainDays",120,actualAppender.getRetainDays());
|
assertEquals("RollingFileAppender.retainDays",120,actualAppender.getRetainDays());
|
||||||
assertEquals("RollingFileAppender.zone","GMT",actualAppender.getZone().getID());
|
assertEquals("RollingFileAppender.zone","GMT",actualAppender.getZone().getID());
|
||||||
|
|
|
@ -39,11 +39,12 @@
|
||||||
</goals>
|
</goals>
|
||||||
<configuration>
|
<configuration>
|
||||||
<tasks>
|
<tasks>
|
||||||
|
<property name="orbit.base.url" value="http://download.eclipse.org/tools/orbit/downloads/drops/R20090529135407/bundles" />
|
||||||
<mkdir dir="${assembly.directory}/lib" />
|
<mkdir dir="${assembly.directory}/lib" />
|
||||||
<get src="http://download.eclipse.org/tools/orbit/downloads/drops/R20090529135407/bundles/javax.servlet_2.5.0.v200806031605.jar" dest="${assembly.directory}/lib/servlet-api-2.5.jar" usetimestamp="true" verbose="true" />
|
<get src="${orbit.base.url}/javax.servlet_2.5.0.v200806031605.jar" dest="${assembly.directory}/lib/servlet-api-2.5.jar" usetimestamp="true" verbose="true" />
|
||||||
<mkdir dir="${assembly.directory}/lib/jndi" />
|
<mkdir dir="${assembly.directory}/lib/jndi" />
|
||||||
<get src="http://download.eclipse.org/tools/orbit/downloads/drops/R20090529135407/bundles/javax.activation_1.1.0.v200905021805.jar" dest="${assembly.directory}/lib/jndi/activation-1.1.jar" usetimestamp="true" verbose="true" />
|
<get src="${orbit.base.url}/javax.activation_1.1.0.v200905021805.jar" dest="${assembly.directory}/lib/jndi/activation-1.1.jar" usetimestamp="true" verbose="true" />
|
||||||
<get src="http://download.eclipse.org/tools/orbit/downloads/drops/R20090529135407/bundles/javax.mail_1.4.0.v200905040518.jar" dest="${assembly.directory}/lib/jndi/mail-1.4.jar" usetimestamp="true" verbose="true" />
|
<get src="${orbit.base.url}/javax.mail_1.4.0.v200905040518.jar" dest="${assembly.directory}/lib/jndi/mail-1.4.jar" usetimestamp="true" verbose="true" />
|
||||||
</tasks>
|
</tasks>
|
||||||
</configuration>
|
</configuration>
|
||||||
</execution>
|
</execution>
|
||||||
|
@ -150,6 +151,16 @@
|
||||||
<includes>**</includes>
|
<includes>**</includes>
|
||||||
<outputDirectory>${assembly.directory}</outputDirectory>
|
<outputDirectory>${assembly.directory}</outputDirectory>
|
||||||
</artifactItem>
|
</artifactItem>
|
||||||
|
<artifactItem>
|
||||||
|
<groupId>org.eclipse.jetty</groupId>
|
||||||
|
<artifactId>jetty-centralized-logging</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
<classifier>config</classifier>
|
||||||
|
<type>jar</type>
|
||||||
|
<overWrite>true</overWrite>
|
||||||
|
<includes>**</includes>
|
||||||
|
<outputDirectory>${assembly.directory}</outputDirectory>
|
||||||
|
</artifactItem>
|
||||||
<artifactItem>
|
<artifactItem>
|
||||||
<groupId>org.eclipse.jetty</groupId>
|
<groupId>org.eclipse.jetty</groupId>
|
||||||
<artifactId>jetty-plus</artifactId>
|
<artifactId>jetty-plus</artifactId>
|
||||||
|
@ -281,6 +292,15 @@
|
||||||
<includes>**</includes>
|
<includes>**</includes>
|
||||||
<outputDirectory>${assembly.directory}/lib</outputDirectory>
|
<outputDirectory>${assembly.directory}/lib</outputDirectory>
|
||||||
</artifactItem>
|
</artifactItem>
|
||||||
|
<artifactItem>
|
||||||
|
<groupId>org.eclipse.jetty</groupId>
|
||||||
|
<artifactId>jetty-centralized-logging</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
<type>jar</type>
|
||||||
|
<overWrite>true</overWrite>
|
||||||
|
<includes>**</includes>
|
||||||
|
<outputDirectory>${assembly.directory}/lib/centralized-logging</outputDirectory>
|
||||||
|
</artifactItem>
|
||||||
<artifactItem>
|
<artifactItem>
|
||||||
<groupId>org.eclipse.jetty</groupId>
|
<groupId>org.eclipse.jetty</groupId>
|
||||||
<artifactId>jetty-deploy</artifactId>
|
<artifactId>jetty-deploy</artifactId>
|
||||||
|
|
Loading…
Reference in New Issue