Commit d5178ede authored by Emmanuel Bourg's avatar Emmanuel Bourg

New upstream version 2.10.0

parent 2d92309a
......@@ -35,10 +35,6 @@ To perform the license release audit, a.k.a. "RAT check", run.
mvn apache-rat:check
To perform a Clirr check on the API module, run
mvn clirr:check -pl log4j-api
To build the site with Java 7, make sure you give Maven enough memory using
`MAVEN_OPTS` with options appropriate for your JVM. Alternatively, you can
build with Java 8 and not deal with `MAVEN_OPTS`.
......@@ -47,7 +43,9 @@ To install the jars in your local Maven repository, from a command line, run:
mvn clean install
Once install is run, you can run the Clirr check on the 1.2 API module:
Once install is run, you can run the Clirr check on the API and 1.2 API modules:
mvn clirr:check -pl log4j-api
mvn clirr:check -pl log4j-1.2-api
......
......@@ -3,37 +3,22 @@
Apache Log4j 2 is an upgrade to Log4j that provides significant improvements over its predecessor, Log4j 1.x,
and provides many of the improvements available in Logback while fixing some inherent problems in Logback's architecture.
[![Jenkins Status](https://builds.apache.org/buildStatus/icon?job=Log4j 2.x)](https://builds.apache.org/job/Log4j%202.x/)
[![Jenkins Status](https://img.shields.io/jenkins/s/https/builds.apache.org/job/Log4j%202.x.svg)](https://builds.apache.org/job/Log4j%202.x/)
[![Travis Status](https://travis-ci.org/apache/logging-log4j2.svg?branch=master)](https://travis-ci.org/apache/logging-log4j2)
[![Coverage Status](https://coveralls.io/repos/github/apache/logging-log4j2/badge.svg?branch=master)](https://coveralls.io/github/apache/logging-log4j2?branch=master)
[![Maven Central](https://img.shields.io/maven-central/v/org.apache.logging.log4j/log4j-api.svg)](http://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-api)
## Usage
Maven users can add the following dependencies to their `pom.xml` file:
## Pull Requests on Github
```xml
<dependencies>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.8</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.8</version>
</dependency>
</dependencies>
```
By sending a pull request you grant the Apache Software Foundation sufficient rights to use and release the submitted
work under the Apache license. You grant the same rights (copyright license, patent license, etc.) to the
Apache Software Foundation as if you have signed a Contributor License Agreement. For contributions that are
judged to be non-trivial, you will be asked to actually signing a Contributor License Agreement.
Gradle users can add the following to their `build.gradle` file:
## Usage
```gradle
dependencies {
compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.8'
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.8'
}
```
Users should refer to [Maven, Ivy, Gradle, and SBT Artifacts](http://logging.apache.org/log4j/2.x/maven-artifacts.html)
on the Log4j web site for instructions on how to include Log4j into their project using their chosen build tool.
Basic usage of the `Logger` API:
......
This diff is collapsed.
......@@ -430,7 +430,7 @@
<foaf:member rdf:nodeID="b5"/>
</foaf:Organization>
<foaf:Organization>
<foaf:name>Magine TV</foaf:name>
<foaf:name>Spotify</foaf:name>
<foaf:member rdf:nodeID="b3"/>
<foaf:member rdf:nodeID="b8"/>
</foaf:Organization>
......
......@@ -20,7 +20,7 @@
<parent>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j</artifactId>
<version>2.9.0</version>
<version>2.10.0</version>
<relativePath>../</relativePath>
</parent>
<artifactId>log4j-1.2-api</artifactId>
......@@ -31,6 +31,7 @@
<log4jParentDir>${basedir}/..</log4jParentDir>
<docLabel>Log4j 1.2 Documentation</docLabel>
<projectDir>/log4j12-api</projectDir>
<module.name>org.apache.log4j</module.name>
</properties>
<dependencies>
<dependency>
......
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache license, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the license for the specific language governing permissions and
* limitations under the license.
*/
package org.apache.log4j;
import org.apache.log4j.spi.ErrorHandler;
import org.apache.log4j.spi.Filter;
import org.apache.log4j.spi.LoggingEvent;
import org.apache.log4j.spi.OptionHandler;
/**
* The base class for Appenders in Log4j 1. Appenders constructed using this are ignored in Log4j 2.
*/
public abstract class AppenderSkeleton implements Appender, OptionHandler {
protected Layout layout;
protected String name;
protected Priority threshold;
protected ErrorHandler errorHandler = new NoOpErrorHandler();
protected Filter headFilter;
protected Filter tailFilter;
protected boolean closed = false;
/**
* Create new instance.
*/
public AppenderSkeleton() {
super();
}
protected AppenderSkeleton(final boolean isActive) {
super();
}
public void activateOptions() {
}
public void addFilter(Filter newFilter) {
if(headFilter == null) {
headFilter = tailFilter = newFilter;
} else {
tailFilter.setNext(newFilter);
tailFilter = newFilter;
}
}
protected abstract void append(LoggingEvent event);
public void clearFilters() {
headFilter = tailFilter = null;
}
public void finalize() {
}
public ErrorHandler getErrorHandler() {
return this.errorHandler;
}
public Filter getFilter() {
return headFilter;
}
public final Filter getFirstFilter() {
return headFilter;
}
public Layout getLayout() {
return layout;
}
public final String getName() {
return this.name;
}
public Priority getThreshold() {
return threshold;
}
public boolean isAsSevereAsThreshold(Priority priority) {
return ((threshold == null) || priority.isGreaterOrEqual(threshold));
}
/**
* This method is never going to be called in Log4j 2 so there isn't much point in having any code in it.
* @param event The LoggingEvent.
*/
public void doAppend(LoggingEvent event) {
}
/**
* Set the {@link ErrorHandler} for this Appender.
*
* @since 0.9.0
*/
public synchronized void setErrorHandler(ErrorHandler eh) {
if (eh != null) {
this.errorHandler = eh;
}
}
public void setLayout(Layout layout) {
this.layout = layout;
}
public void setName(String name) {
this.name = name;
}
public void setThreshold(Priority threshold) {
this.threshold = threshold;
}
public static class NoOpErrorHandler implements ErrorHandler {
@Override
public void setLogger(Logger logger) {
}
@Override
public void error(String message, Exception e, int errorCode) {
}
@Override
public void error(String message) {
}
@Override
public void error(String message, Exception e, int errorCode, LoggingEvent event) {
}
@Override
public void setAppender(Appender appender) {
}
@Override
public void setBackupAppender(Appender appender) {
}
}
}
......@@ -16,6 +16,8 @@
*/
package org.apache.log4j.layout;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.nio.charset.StandardCharsets;
import java.util.List;
......@@ -107,16 +109,12 @@ public final class Log4j1XmlLayout extends AbstractStringLayout {
}
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
final
Throwable thrown = event.getThrown();
final Throwable thrown = event.getThrown();
if (thrown != null) {
buf.append("<log4j:throwable><![CDATA[");
buf.append(thrown.toString());
buf.append("\r\n");
for (final StackTraceElement element : thrown.getStackTrace()) {
Transform.appendEscapingCData(buf, "\tat " + element.toString());
buf.append("\r\n");
}
final StringWriter w = new StringWriter();
thrown.printStackTrace(new PrintWriter(w));
Transform.appendEscapingCData(buf, w.toString());
buf.append("]]></log4j:throwable>\r\n");
}
......
......@@ -14,20 +14,13 @@
* See the license for the specific language governing permissions and
* limitations under the license.
*/
package org.apache.logging.log4j.web;
package org.apache.log4j.spi;
import org.apache.logging.log4j.util.PropertiesUtil;
import org.junit.Test;
import static org.junit.Assert.*;
/**
*
* Log4j 1 Interface for dealing with configuration. Ignored in Log4j 2.
*/
public class ShutdownPropertyTest {
public interface OptionHandler {
@Test
public void testWebProperty() {
assertFalse(PropertiesUtil.getProperties().getBooleanProperty("log4j.shutdownHookEnabled", true));
}
void activateOptions();
}
......@@ -161,11 +161,17 @@ public class Log4j1ConfigurationFactoryTest {
@Test
public void testSystemProperties1() throws Exception {
final Configuration configuration = getConfiguration("config-1.2/log4j-system-properties-1.properties");
final RollingFileAppender appender = configuration.getAppender("RFA");
final String tempFileName = System.getProperty("java.io.tmpdir") + "/hadoop.log";
System.out.println("expected: " + tempFileName + " Actual: " + appender.getFileName());
assertEquals(tempFileName, appender.getFileName());
final Path tempFilePath = new File(tempFileName).toPath();
Files.deleteIfExists(tempFilePath);
try {
final Configuration configuration = getConfiguration("config-1.2/log4j-system-properties-1.properties");
final RollingFileAppender appender = configuration.getAppender("RFA");
System.out.println("expected: " + tempFileName + " Actual: " + appender.getFileName());
assertEquals(tempFileName, appender.getFileName());
} finally {
Files.deleteIfExists(tempFilePath);
}
}
@Test
......
......@@ -20,7 +20,7 @@
<parent>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j</artifactId>
<version>2.9.0</version>
<version>2.10.0</version>
<relativePath>../</relativePath>
</parent>
<artifactId>log4j-api-java9</artifactId>
......
......@@ -31,6 +31,18 @@
<includes>
<include>**/*.class</include>
</includes>
<excludes>
<exclude>module-info.class</exclude>
<exclude>**/Dummy.class</exclude>
<exclude>**/spi/Provider.class</exclude>
</excludes>
</fileSet>
<fileSet>
<directory>${project.build.outputDirectory}</directory>
<outputDirectory>/classes</outputDirectory>
<includes>
<include>module-info.class</include>
</includes>
</fileSet>
</fileSets>
</assembly>
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache license, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the license for the specific language governing permissions and
* limitations under the license.
*/
module org.apache.logging.log4j {
exports org.apache.logging.log4j;
exports org.apache.logging.log4j.message;
exports org.apache.logging.log4j.simple;
exports org.apache.logging.log4j.spi;
exports org.apache.logging.log4j.status;
exports org.apache.logging.log4j.util;
uses org.apache.logging.log4j.spi.Provider;
}
\ No newline at end of file
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache license, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the license for the specific language governing permissions and
* limitations under the license.
*/
package org.apache.logging.log4j;
/**
* This is a dummy class and is only here to allow module-info.java to compile. It will not
* be copied into the log4j-api module.
*/
public class Dummy {
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache license, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the license for the specific language governing permissions and
* limitations under the license.
*/
package org.apache.logging.log4j.message;
/**
* This is a dummy class and is only here to allow module-info.java to compile. It will not
* be copied into the log4j-api module.
*/
public class Dummy {
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache license, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the license for the specific language governing permissions and
* limitations under the license.
*/
package org.apache.logging.log4j.simple;
/**
* This is a dummy class and is only here to allow module-info.java to compile. It will not
* be copied into the log4j-api module.
*/
public class Dummy {
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache license, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the license for the specific language governing permissions and
* limitations under the license.
*/
package org.apache.logging.log4j.spi;
/**
* This is a dummy class and is only here to allow module-info.java to compile. It will not
* be copied into the log4j-api module.
*/
public class Provider {
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache license, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the license for the specific language governing permissions and
* limitations under the license.
*/
package org.apache.logging.log4j.status;
/**
* This is a dummy class and is only here to allow module-info.java to compile. It will not
* be copied into the log4j-api module.
*/
public class Dummy {
}
......@@ -68,8 +68,12 @@ public class StackLocator {
}
public StackTraceElement calcLocation(final String fqcnOfLogger) {
return stackWalker.walk(s -> s.dropWhile(f -> f.getClassName().equals(fqcnOfLogger)).
dropWhile(f -> f.getClassName().equals(fqcnOfLogger)).findFirst()).get().toStackTraceElement();
return stackWalker.walk(
s -> s.dropWhile(f -> !f.getClassName().equals(fqcnOfLogger)) // drop the top frames until we reach the logger
.dropWhile(f -> f.getClassName().equals(fqcnOfLogger)) // drop the logger frames
.findFirst())
.get()
.toStackTraceElement();
}
public StackTraceElement getStackTraceElement(final int depth) {
......
......@@ -16,14 +16,17 @@
*/
package org.apache.logging.log4j.util;
import java.util.Stack;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.BlockJUnit4ClassRunner;
import org.junit.runners.ParentRunner;
import static org.junit.Assert.*;
import java.util.Stack;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
@RunWith(BlockJUnit4ClassRunner.class)
public class StackLocatorTest {
......@@ -91,6 +94,47 @@ public class StackLocatorTest {
assertEquals("Incorrect class", this.getClass(), clazz);
}
private final class Foo {
private StackTraceElement foo() {
return new Bar().bar();
}
}
private final class Bar {
private StackTraceElement bar() {
return baz();
}
private StackTraceElement baz() {
return quux();
}
}
private StackTraceElement quux() {
return stackLocator.calcLocation("org.apache.logging.log4j.util.StackLocatorTest$Bar");
}