-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split off YAML configuration into its own module
This splits `YamlConfiguration` into its own module and removes `jackson-dataformat-yaml` from `log4j-core`'s optional dependencies.
- Loading branch information
Showing
28 changed files
with
342 additions
and
274 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ 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. | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.apache.logging.log4j</groupId> | ||
<artifactId>log4j</artifactId> | ||
<version>${revision}</version> | ||
<relativePath>../log4j-parent</relativePath> | ||
</parent> | ||
|
||
<artifactId>log4j-config-yaml</artifactId> | ||
|
||
<dependencies> | ||
|
||
<dependency> | ||
<groupId>org.apache.logging.log4j</groupId> | ||
<artifactId>log4j-core</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-databind</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.fasterxml.jackson.dataformat</groupId> | ||
<artifactId>jackson-dataformat-yaml</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.logging.log4j</groupId> | ||
<artifactId>log4j-core-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<annotationProcessorPaths combine.children="append"> | ||
<path> | ||
<groupId>org.apache.logging.log4j</groupId> | ||
<artifactId>log4j-plugin-processor</artifactId> | ||
<version>${project.version}</version> | ||
</path> | ||
</annotationProcessorPaths> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...yaml/src/test/java/org/apache/logging/log4j/config/yaml/YamlConfigurationFactoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* 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.config.yaml; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import org.apache.logging.log4j.core.LoggerContext; | ||
import org.apache.logging.log4j.core.config.AbstractConfigurationFactoryTest; | ||
import org.apache.logging.log4j.core.test.junit.LoggerContextSource; | ||
import org.apache.logging.log4j.test.junit.TempLoggingDir; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class YamlConfigurationFactoryTest extends AbstractConfigurationFactoryTest { | ||
|
||
@TempLoggingDir | ||
private static Path loggingPath; | ||
|
||
@Test | ||
@LoggerContextSource("YamlConfigurationFactoryTest.yaml") | ||
void yamlConfiguration(final LoggerContext context) throws IOException { | ||
checkConfiguration(context); | ||
final Path logFile = loggingPath.resolve("test-yaml.log"); | ||
checkFileLogger(context, logFile); | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
86 changes: 86 additions & 0 deletions
86
.../src/main/java/org/apache/logging/log4j/core/config/AbstractConfigurationFactoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* 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.core.config; | ||
|
||
import static org.apache.logging.log4j.util.Unbox.box; | ||
import static org.junit.jupiter.api.Assertions.assertAll; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
import java.util.Map; | ||
import org.apache.logging.log4j.Level; | ||
import org.apache.logging.log4j.core.Appender; | ||
import org.apache.logging.log4j.core.Filter; | ||
import org.apache.logging.log4j.core.Logger; | ||
import org.apache.logging.log4j.core.LoggerContext; | ||
import org.apache.logging.log4j.core.appender.ConsoleAppender; | ||
import org.apache.logging.log4j.core.filter.ThreadContextMapFilter; | ||
import org.apache.logging.log4j.util.Strings; | ||
|
||
/** | ||
* Common base class for configuration factory tests. | ||
*/ | ||
public abstract class AbstractConfigurationFactoryTest { | ||
|
||
private static final String LOGGER_NAME = "org.apache.logging.log4j.test1.Test"; | ||
private static final String FILE_LOGGER_NAME = "org.apache.logging.log4j.test2.Test"; | ||
private static final String APPENDER_NAME = "STDOUT"; | ||
|
||
/** | ||
* Runs various configuration checks on a configured LoggerContext that should match the equivalent configuration in | ||
* {@code log4j-test1.xml}. | ||
*/ | ||
protected static void checkConfiguration(final LoggerContext context) { | ||
final Configuration configuration = context.getConfiguration(); | ||
final Map<String, Appender> appenders = configuration.getAppenders(); | ||
// these used to be separate tests | ||
assertAll( | ||
() -> assertNotNull(appenders), | ||
() -> assertEquals(3, appenders.size()), | ||
() -> assertNotNull(configuration.getLoggerContext()), | ||
() -> assertEquals(configuration.getRootLogger(), configuration.getLoggerConfig(Strings.EMPTY)), | ||
() -> assertThrows(NullPointerException.class, () -> configuration.getLoggerConfig(null))); | ||
|
||
final Logger logger = context.getLogger(LOGGER_NAME); | ||
assertEquals(Level.DEBUG, logger.getLevel()); | ||
|
||
assertEquals(1, logger.filterCount()); | ||
final Iterator<Filter> filterIterator = logger.getFilters(); | ||
assertTrue(filterIterator.hasNext()); | ||
assertTrue(filterIterator.next() instanceof ThreadContextMapFilter); | ||
|
||
final Appender appender = appenders.get(APPENDER_NAME); | ||
assertTrue(appender instanceof ConsoleAppender); | ||
assertEquals(APPENDER_NAME, appender.getName()); | ||
} | ||
|
||
protected static void checkFileLogger(final LoggerContext context, final Path logFile) throws IOException { | ||
final long currentThreadId = Thread.currentThread().getId(); | ||
final Logger logger = context.getLogger(FILE_LOGGER_NAME); | ||
logger.debug("Greetings from ConfigurationFactoryTest in thread#{}", box(currentThreadId)); | ||
final List<String> lines = Files.readAllLines(logFile); | ||
assertEquals(1, lines.size()); | ||
assertTrue(lines.get(0).endsWith(Long.toString(currentThreadId))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.