Repository: logging-log4j2 Updated Branches: refs/heads/master d4af84424 -> cdc19e40e
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/cdc19e40/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/IfFileName.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/IfFileName.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/IfFileName.java index ad958e4..9eeecf4 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/IfFileName.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/IfFileName.java @@ -1,149 +1,150 @@ -/* - * 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.appender.rolling.action; - -import java.nio.file.FileSystem; -import java.nio.file.FileSystems; -import java.nio.file.Path; -import java.nio.file.PathMatcher; -import java.nio.file.attribute.BasicFileAttributes; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.regex.Pattern; - -import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.core.config.plugins.Plugin; -import org.apache.logging.log4j.core.config.plugins.PluginAttribute; -import org.apache.logging.log4j.core.config.plugins.PluginElement; -import org.apache.logging.log4j.core.config.plugins.PluginFactory; -import org.apache.logging.log4j.status.StatusLogger; - -/** - * PathCondition that accepts files for deletion if their relative path matches either a glob pattern or a regular - * expression. If both a regular expression and a glob pattern are specified the glob pattern is used and the regular - * expression is ignored. - * <p> - * The regular expression is a pattern as defined by the {@link Pattern} class. A glob is a simplified pattern - * expression described in {@link FileSystem#getPathMatcher(String)}. - */ -@Plugin(name = "IfFileName", category = "Core", printObject = true) -public final class IfFileName implements PathCondition { - private static final Logger LOGGER = StatusLogger.getLogger(); - private final PathMatcher pathMatcher; - private final String syntaxAndPattern; - private final PathCondition[] nestedConditions; - - /** - * Constructs a FileNameFilter filter. If both a regular expression and a glob pattern are specified the glob - * pattern is used and the regular expression is ignored. - * - * @param glob the baseDir-relative path pattern of the files to delete (may contain '*' and '?' wildcarts) - * @param regex the regular expression that matches the baseDir-relative path of the file(s) to delete - * @param nestedConditions nested conditions to evaluate if this condition accepts a path - */ - private IfFileName(final String glob, final String regex, final PathCondition[] nestedConditions) { - if (regex == null && glob == null) { - throw new IllegalArgumentException("Specify either a path glob or a regular expression. " - + "Both cannot be null."); - } - this.syntaxAndPattern = createSyntaxAndPatternString(glob, regex); - this.pathMatcher = FileSystems.getDefault().getPathMatcher(syntaxAndPattern); - this.nestedConditions = nestedConditions == null ? new PathCondition[0] : Arrays.copyOf(nestedConditions, - nestedConditions.length); - } - - static String createSyntaxAndPatternString(final String glob, final String regex) { - if (glob != null) { - return glob.startsWith("glob:") ? glob : "glob:" + glob; - } - return regex.startsWith("regex:") ? regex : "regex:" + regex; - } - - /** - * Returns the baseDir-relative path pattern of the files to delete. The returned string takes the form - * {@code syntax:pattern} where syntax is one of "glob" or "regex" and the pattern is either a {@linkplain Pattern - * regular expression} or a simplified pattern expression described under "glob" in - * {@link FileSystem#getPathMatcher(String)}. - * - * @return relative path of the file(s) to delete (may contain regular expression or wildcarts) - */ - public String getSyntaxAndPattern() { - return syntaxAndPattern; - } - - public List<PathCondition> getNestedConditions() { - return Collections.unmodifiableList(Arrays.asList(nestedConditions)); - } - - /* - * (non-Javadoc) - * - * @see org.apache.logging.log4j.core.appender.rolling.action.PathCondition#accept(java.nio.file.Path, - * java.nio.file.Path, java.nio.file.attribute.BasicFileAttributes) - */ - @Override - public boolean accept(final Path basePath, final Path relativePath, final BasicFileAttributes attrs) { - final boolean result = pathMatcher.matches(relativePath); - - final String match = result ? "matches" : "does not match"; - final String accept = result ? "ACCEPTED" : "REJECTED"; - LOGGER.trace("IfFileName {}: '{}' {} relative path '{}'", accept, syntaxAndPattern, match, relativePath); - if (result) { - return IfAll.accept(nestedConditions, basePath, relativePath, attrs); - } - return result; - } - - /* - * (non-Javadoc) - * - * @see org.apache.logging.log4j.core.appender.rolling.action.PathCondition#beforeFileTreeWalk() - */ - @Override - public void beforeFileTreeWalk() { - IfAll.beforeFileTreeWalk(nestedConditions); - } - - /** - * Creates a IfFileName condition that returns true if either the specified - * {@linkplain FileSystem#getPathMatcher(String) glob pattern} or the regular expression matches the relative path. - * If both a regular expression and a glob pattern are specified the glob pattern is used and the regular expression - * is ignored. - * - * @param glob the baseDir-relative path pattern of the files to delete (may contain '*' and '?' wildcarts) - * @param regex the regular expression that matches the baseDir-relative path of the file(s) to delete - * @param nestedConditions nested conditions to evaluate if this condition accepts a path - * @return A IfFileName condition. - * @see FileSystem#getPathMatcher(String) - */ - @PluginFactory - public static IfFileName createNameCondition( // - // @formatter:off - @PluginAttribute("glob") final String glob, // - @PluginAttribute("regex") final String regex, // - @PluginElement("PathConditions") final PathCondition... nestedConditions) { - // @formatter:on - return new IfFileName(glob, regex, nestedConditions); - } - - @Override - public String toString() { - final String nested = nestedConditions.length == 0 ? "" : " AND " + Arrays.toString(nestedConditions); - return "IfFileName(" + syntaxAndPattern + nested + ")"; - } -} +/* + * 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.appender.rolling.action; + +import java.nio.file.FileSystem; +import java.nio.file.FileSystems; +import java.nio.file.Path; +import java.nio.file.PathMatcher; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.regex.Pattern; + +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.core.Core; +import org.apache.logging.log4j.core.config.plugins.Plugin; +import org.apache.logging.log4j.core.config.plugins.PluginAttribute; +import org.apache.logging.log4j.core.config.plugins.PluginElement; +import org.apache.logging.log4j.core.config.plugins.PluginFactory; +import org.apache.logging.log4j.status.StatusLogger; + +/** + * PathCondition that accepts files for deletion if their relative path matches either a glob pattern or a regular + * expression. If both a regular expression and a glob pattern are specified the glob pattern is used and the regular + * expression is ignored. + * <p> + * The regular expression is a pattern as defined by the {@link Pattern} class. A glob is a simplified pattern + * expression described in {@link FileSystem#getPathMatcher(String)}. + */ +@Plugin(name = "IfFileName", category = Core.CATEGORY_NAME, printObject = true) +public final class IfFileName implements PathCondition { + private static final Logger LOGGER = StatusLogger.getLogger(); + private final PathMatcher pathMatcher; + private final String syntaxAndPattern; + private final PathCondition[] nestedConditions; + + /** + * Constructs a FileNameFilter filter. If both a regular expression and a glob pattern are specified the glob + * pattern is used and the regular expression is ignored. + * + * @param glob the baseDir-relative path pattern of the files to delete (may contain '*' and '?' wildcarts) + * @param regex the regular expression that matches the baseDir-relative path of the file(s) to delete + * @param nestedConditions nested conditions to evaluate if this condition accepts a path + */ + private IfFileName(final String glob, final String regex, final PathCondition[] nestedConditions) { + if (regex == null && glob == null) { + throw new IllegalArgumentException("Specify either a path glob or a regular expression. " + + "Both cannot be null."); + } + this.syntaxAndPattern = createSyntaxAndPatternString(glob, regex); + this.pathMatcher = FileSystems.getDefault().getPathMatcher(syntaxAndPattern); + this.nestedConditions = nestedConditions == null ? new PathCondition[0] : Arrays.copyOf(nestedConditions, + nestedConditions.length); + } + + static String createSyntaxAndPatternString(final String glob, final String regex) { + if (glob != null) { + return glob.startsWith("glob:") ? glob : "glob:" + glob; + } + return regex.startsWith("regex:") ? regex : "regex:" + regex; + } + + /** + * Returns the baseDir-relative path pattern of the files to delete. The returned string takes the form + * {@code syntax:pattern} where syntax is one of "glob" or "regex" and the pattern is either a {@linkplain Pattern + * regular expression} or a simplified pattern expression described under "glob" in + * {@link FileSystem#getPathMatcher(String)}. + * + * @return relative path of the file(s) to delete (may contain regular expression or wildcarts) + */ + public String getSyntaxAndPattern() { + return syntaxAndPattern; + } + + public List<PathCondition> getNestedConditions() { + return Collections.unmodifiableList(Arrays.asList(nestedConditions)); + } + + /* + * (non-Javadoc) + * + * @see org.apache.logging.log4j.core.appender.rolling.action.PathCondition#accept(java.nio.file.Path, + * java.nio.file.Path, java.nio.file.attribute.BasicFileAttributes) + */ + @Override + public boolean accept(final Path basePath, final Path relativePath, final BasicFileAttributes attrs) { + final boolean result = pathMatcher.matches(relativePath); + + final String match = result ? "matches" : "does not match"; + final String accept = result ? "ACCEPTED" : "REJECTED"; + LOGGER.trace("IfFileName {}: '{}' {} relative path '{}'", accept, syntaxAndPattern, match, relativePath); + if (result) { + return IfAll.accept(nestedConditions, basePath, relativePath, attrs); + } + return result; + } + + /* + * (non-Javadoc) + * + * @see org.apache.logging.log4j.core.appender.rolling.action.PathCondition#beforeFileTreeWalk() + */ + @Override + public void beforeFileTreeWalk() { + IfAll.beforeFileTreeWalk(nestedConditions); + } + + /** + * Creates a IfFileName condition that returns true if either the specified + * {@linkplain FileSystem#getPathMatcher(String) glob pattern} or the regular expression matches the relative path. + * If both a regular expression and a glob pattern are specified the glob pattern is used and the regular expression + * is ignored. + * + * @param glob the baseDir-relative path pattern of the files to delete (may contain '*' and '?' wildcarts) + * @param regex the regular expression that matches the baseDir-relative path of the file(s) to delete + * @param nestedConditions nested conditions to evaluate if this condition accepts a path + * @return A IfFileName condition. + * @see FileSystem#getPathMatcher(String) + */ + @PluginFactory + public static IfFileName createNameCondition( // + // @formatter:off + @PluginAttribute("glob") final String glob, // + @PluginAttribute("regex") final String regex, // + @PluginElement("PathConditions") final PathCondition... nestedConditions) { + // @formatter:on + return new IfFileName(glob, regex, nestedConditions); + } + + @Override + public String toString() { + final String nested = nestedConditions.length == 0 ? "" : " AND " + Arrays.toString(nestedConditions); + return "IfFileName(" + syntaxAndPattern + nested + ")"; + } +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/cdc19e40/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/IfLastModified.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/IfLastModified.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/IfLastModified.java index a3956c1..4a3f7e7 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/IfLastModified.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/IfLastModified.java @@ -1,113 +1,114 @@ -/* - * 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.appender.rolling.action; - -import java.nio.file.Path; -import java.nio.file.attribute.BasicFileAttributes; -import java.nio.file.attribute.FileTime; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Objects; - -import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.core.config.plugins.Plugin; -import org.apache.logging.log4j.core.config.plugins.PluginAttribute; -import org.apache.logging.log4j.core.config.plugins.PluginElement; -import org.apache.logging.log4j.core.config.plugins.PluginFactory; -import org.apache.logging.log4j.core.util.Clock; -import org.apache.logging.log4j.core.util.ClockFactory; -import org.apache.logging.log4j.status.StatusLogger; - -/** - * PathCondition that accepts paths that are older than the specified duration. - */ -@Plugin(name = "IfLastModified", category = "Core", printObject = true) -public final class IfLastModified implements PathCondition { - private static final Logger LOGGER = StatusLogger.getLogger(); - private static final Clock CLOCK = ClockFactory.getClock(); - - private final Duration age; - private final PathCondition[] nestedConditions; - - private IfLastModified(final Duration age, final PathCondition[] nestedConditions) { - this.age = Objects.requireNonNull(age, "age"); - this.nestedConditions = nestedConditions == null ? new PathCondition[0] : Arrays.copyOf(nestedConditions, - nestedConditions.length); - } - - public Duration getAge() { - return age; - } - - public List<PathCondition> getNestedConditions() { - return Collections.unmodifiableList(Arrays.asList(nestedConditions)); - } - - /* - * (non-Javadoc) - * - * @see org.apache.logging.log4j.core.appender.rolling.action.PathCondition#accept(java.nio.file.Path, - * java.nio.file.Path, java.nio.file.attribute.BasicFileAttributes) - */ - @Override - public boolean accept(final Path basePath, final Path relativePath, final BasicFileAttributes attrs) { - final FileTime fileTime = attrs.lastModifiedTime(); - final long millis = fileTime.toMillis(); - final long ageMillis = CLOCK.currentTimeMillis() - millis; - final boolean result = ageMillis >= age.toMillis(); - final String match = result ? ">=" : "<"; - final String accept = result ? "ACCEPTED" : "REJECTED"; - LOGGER.trace("IfLastModified {}: {} ageMillis '{}' {} '{}'", accept, relativePath, ageMillis, match, age); - if (result) { - return IfAll.accept(nestedConditions, basePath, relativePath, attrs); - } - return result; - } - - /* - * (non-Javadoc) - * - * @see org.apache.logging.log4j.core.appender.rolling.action.PathCondition#beforeFileTreeWalk() - */ - @Override - public void beforeFileTreeWalk() { - IfAll.beforeFileTreeWalk(nestedConditions); - } - - /** - * Create an IfLastModified condition. - * - * @param age The path age that is accepted by this condition. Must be a valid Duration. - * @param nestedConditions nested conditions to evaluate if this condition accepts a path - * @return An IfLastModified condition. - */ - @PluginFactory - public static IfLastModified createAgeCondition( // - // @formatter:off - @PluginAttribute("age") final Duration age, // - @PluginElement("PathConditions") final PathCondition... nestedConditions) { - // @formatter:on - return new IfLastModified(age, nestedConditions); - } - - @Override - public String toString() { - final String nested = nestedConditions.length == 0 ? "" : " AND " + Arrays.toString(nestedConditions); - return "IfLastModified(age=" + age + nested + ")"; - } -} +/* + * 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.appender.rolling.action; + +import java.nio.file.Path; +import java.nio.file.attribute.BasicFileAttributes; +import java.nio.file.attribute.FileTime; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Objects; + +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.core.Core; +import org.apache.logging.log4j.core.config.plugins.Plugin; +import org.apache.logging.log4j.core.config.plugins.PluginAttribute; +import org.apache.logging.log4j.core.config.plugins.PluginElement; +import org.apache.logging.log4j.core.config.plugins.PluginFactory; +import org.apache.logging.log4j.core.util.Clock; +import org.apache.logging.log4j.core.util.ClockFactory; +import org.apache.logging.log4j.status.StatusLogger; + +/** + * PathCondition that accepts paths that are older than the specified duration. + */ +@Plugin(name = "IfLastModified", category = Core.CATEGORY_NAME, printObject = true) +public final class IfLastModified implements PathCondition { + private static final Logger LOGGER = StatusLogger.getLogger(); + private static final Clock CLOCK = ClockFactory.getClock(); + + private final Duration age; + private final PathCondition[] nestedConditions; + + private IfLastModified(final Duration age, final PathCondition[] nestedConditions) { + this.age = Objects.requireNonNull(age, "age"); + this.nestedConditions = nestedConditions == null ? new PathCondition[0] : Arrays.copyOf(nestedConditions, + nestedConditions.length); + } + + public Duration getAge() { + return age; + } + + public List<PathCondition> getNestedConditions() { + return Collections.unmodifiableList(Arrays.asList(nestedConditions)); + } + + /* + * (non-Javadoc) + * + * @see org.apache.logging.log4j.core.appender.rolling.action.PathCondition#accept(java.nio.file.Path, + * java.nio.file.Path, java.nio.file.attribute.BasicFileAttributes) + */ + @Override + public boolean accept(final Path basePath, final Path relativePath, final BasicFileAttributes attrs) { + final FileTime fileTime = attrs.lastModifiedTime(); + final long millis = fileTime.toMillis(); + final long ageMillis = CLOCK.currentTimeMillis() - millis; + final boolean result = ageMillis >= age.toMillis(); + final String match = result ? ">=" : "<"; + final String accept = result ? "ACCEPTED" : "REJECTED"; + LOGGER.trace("IfLastModified {}: {} ageMillis '{}' {} '{}'", accept, relativePath, ageMillis, match, age); + if (result) { + return IfAll.accept(nestedConditions, basePath, relativePath, attrs); + } + return result; + } + + /* + * (non-Javadoc) + * + * @see org.apache.logging.log4j.core.appender.rolling.action.PathCondition#beforeFileTreeWalk() + */ + @Override + public void beforeFileTreeWalk() { + IfAll.beforeFileTreeWalk(nestedConditions); + } + + /** + * Create an IfLastModified condition. + * + * @param age The path age that is accepted by this condition. Must be a valid Duration. + * @param nestedConditions nested conditions to evaluate if this condition accepts a path + * @return An IfLastModified condition. + */ + @PluginFactory + public static IfLastModified createAgeCondition( // + // @formatter:off + @PluginAttribute("age") final Duration age, // + @PluginElement("PathConditions") final PathCondition... nestedConditions) { + // @formatter:on + return new IfLastModified(age, nestedConditions); + } + + @Override + public String toString() { + final String nested = nestedConditions.length == 0 ? "" : " AND " + Arrays.toString(nestedConditions); + return "IfLastModified(age=" + age + nested + ")"; + } +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/cdc19e40/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/IfNot.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/IfNot.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/IfNot.java index 37d2eff..9f2246e 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/IfNot.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/IfNot.java @@ -1,77 +1,78 @@ -/* - * 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.appender.rolling.action; - -import java.nio.file.Path; -import java.nio.file.attribute.BasicFileAttributes; -import java.util.Objects; - -import org.apache.logging.log4j.core.config.plugins.Plugin; -import org.apache.logging.log4j.core.config.plugins.PluginElement; -import org.apache.logging.log4j.core.config.plugins.PluginFactory; - -/** - * Wrapper {@code PathCondition} that accepts objects that are rejected by the wrapped component filter. - */ -@Plugin(name = "IfNot", category = "Core", printObject = true) -public final class IfNot implements PathCondition { - - private final PathCondition negate; - - private IfNot(final PathCondition negate) { - this.negate = Objects.requireNonNull(negate, "filter"); - } - - public PathCondition getWrappedFilter() { - return negate; - } - - /* - * (non-Javadoc) - * @see org.apache.logging.log4j.core.appender.rolling.action.PathCondition#accept(java.nio.file.Path, java.nio.file.Path, java.nio.file.attribute.BasicFileAttributes) - */ - @Override - public boolean accept(final Path baseDir, final Path relativePath, final BasicFileAttributes attrs) { - return !negate.accept(baseDir, relativePath, attrs); - } - - /* - * (non-Javadoc) - * @see org.apache.logging.log4j.core.appender.rolling.action.PathCondition#beforeFileTreeWalk() - */ - @Override - public void beforeFileTreeWalk() { - negate.beforeFileTreeWalk(); - } - - /** - * Create an IfNot PathCondition. - * - * @param condition The condition to negate. - * @return An IfNot PathCondition. - */ - @PluginFactory - public static IfNot createNotCondition( // - @PluginElement("PathConditions") final PathCondition condition) { - return new IfNot(condition); - } - - @Override - public String toString() { - return "IfNot(" + negate + ")"; - } -} +/* + * 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.appender.rolling.action; + +import java.nio.file.Path; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.Objects; + +import org.apache.logging.log4j.core.Core; +import org.apache.logging.log4j.core.config.plugins.Plugin; +import org.apache.logging.log4j.core.config.plugins.PluginElement; +import org.apache.logging.log4j.core.config.plugins.PluginFactory; + +/** + * Wrapper {@code PathCondition} that accepts objects that are rejected by the wrapped component filter. + */ +@Plugin(name = "IfNot", category = Core.CATEGORY_NAME, printObject = true) +public final class IfNot implements PathCondition { + + private final PathCondition negate; + + private IfNot(final PathCondition negate) { + this.negate = Objects.requireNonNull(negate, "filter"); + } + + public PathCondition getWrappedFilter() { + return negate; + } + + /* + * (non-Javadoc) + * @see org.apache.logging.log4j.core.appender.rolling.action.PathCondition#accept(java.nio.file.Path, java.nio.file.Path, java.nio.file.attribute.BasicFileAttributes) + */ + @Override + public boolean accept(final Path baseDir, final Path relativePath, final BasicFileAttributes attrs) { + return !negate.accept(baseDir, relativePath, attrs); + } + + /* + * (non-Javadoc) + * @see org.apache.logging.log4j.core.appender.rolling.action.PathCondition#beforeFileTreeWalk() + */ + @Override + public void beforeFileTreeWalk() { + negate.beforeFileTreeWalk(); + } + + /** + * Create an IfNot PathCondition. + * + * @param condition The condition to negate. + * @return An IfNot PathCondition. + */ + @PluginFactory + public static IfNot createNotCondition( // + @PluginElement("PathConditions") final PathCondition condition) { + return new IfNot(condition); + } + + @Override + public String toString() { + return "IfNot(" + negate + ")"; + } +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/cdc19e40/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/PathSortByModificationTime.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/PathSortByModificationTime.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/PathSortByModificationTime.java index d5a91ce..75ebe20 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/PathSortByModificationTime.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/PathSortByModificationTime.java @@ -1,89 +1,90 @@ -/* - * 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.appender.rolling.action; - -import java.io.Serializable; - -import org.apache.logging.log4j.core.config.plugins.Plugin; -import org.apache.logging.log4j.core.config.plugins.PluginAttribute; -import org.apache.logging.log4j.core.config.plugins.PluginFactory; - -/** - * {@link PathSorter} that sorts path by their LastModified attribute. - */ -@Plugin(name = "SortByModificationTime", category = "Core", printObject = true) -public class PathSortByModificationTime implements PathSorter, Serializable { - - private static final long serialVersionUID = 1L; - - private final boolean recentFirst; - private final int multiplier; - - /** - * Constructs a new SortByModificationTime sorter. - * - * @param recentFirst if true, most recently modified paths should come first - */ - public PathSortByModificationTime(final boolean recentFirst) { - this.recentFirst = recentFirst; - this.multiplier = recentFirst ? 1 : -1; - } - - /** - * Create a PathSorter that sorts by lastModified time. - * - * @param recentFirst if true, most recently modified paths should come first. - * @return A PathSorter. - */ - @PluginFactory - public static PathSorter createSorter( // - @PluginAttribute(value = "recentFirst", defaultBoolean = true) final boolean recentFirst) { - return new PathSortByModificationTime(recentFirst); - } - - /** - * Returns whether this sorter sorts recent files first. - * - * @return whether this sorter sorts recent files first - */ - public boolean isRecentFirst() { - return recentFirst; - } - - /* - * (non-Javadoc) - * - * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) - */ - @Override - public int compare(final PathWithAttributes path1, final PathWithAttributes path2) { - final long lastModified1 = path1.getAttributes().lastModifiedTime().toMillis(); - final long lastModified2 = path2.getAttributes().lastModifiedTime().toMillis(); - int result = Long.signum(lastModified2 - lastModified1); - if (result == 0) { // if same time compare paths lexicographically - try { - // assuming paths contain counters and dates, use reverse lexicographical order: - // 20151129 before 20151128, path-2.log before path-1.log - result = path2.getPath().compareTo(path1.getPath()); - } catch (final ClassCastException ex) { - result = path2.getPath().toString().compareTo(path1.getPath().toString()); - } - } - return multiplier * result; - } -} +/* + * 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.appender.rolling.action; + +import java.io.Serializable; + +import org.apache.logging.log4j.core.Core; +import org.apache.logging.log4j.core.config.plugins.Plugin; +import org.apache.logging.log4j.core.config.plugins.PluginAttribute; +import org.apache.logging.log4j.core.config.plugins.PluginFactory; + +/** + * {@link PathSorter} that sorts path by their LastModified attribute. + */ +@Plugin(name = "SortByModificationTime", category = Core.CATEGORY_NAME, printObject = true) +public class PathSortByModificationTime implements PathSorter, Serializable { + + private static final long serialVersionUID = 1L; + + private final boolean recentFirst; + private final int multiplier; + + /** + * Constructs a new SortByModificationTime sorter. + * + * @param recentFirst if true, most recently modified paths should come first + */ + public PathSortByModificationTime(final boolean recentFirst) { + this.recentFirst = recentFirst; + this.multiplier = recentFirst ? 1 : -1; + } + + /** + * Create a PathSorter that sorts by lastModified time. + * + * @param recentFirst if true, most recently modified paths should come first. + * @return A PathSorter. + */ + @PluginFactory + public static PathSorter createSorter( // + @PluginAttribute(value = "recentFirst", defaultBoolean = true) final boolean recentFirst) { + return new PathSortByModificationTime(recentFirst); + } + + /** + * Returns whether this sorter sorts recent files first. + * + * @return whether this sorter sorts recent files first + */ + public boolean isRecentFirst() { + return recentFirst; + } + + /* + * (non-Javadoc) + * + * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) + */ + @Override + public int compare(final PathWithAttributes path1, final PathWithAttributes path2) { + final long lastModified1 = path1.getAttributes().lastModifiedTime().toMillis(); + final long lastModified2 = path2.getAttributes().lastModifiedTime().toMillis(); + int result = Long.signum(lastModified2 - lastModified1); + if (result == 0) { // if same time compare paths lexicographically + try { + // assuming paths contain counters and dates, use reverse lexicographical order: + // 20151129 before 20151128, path-2.log before path-1.log + result = path2.getPath().compareTo(path1.getPath()); + } catch (final ClassCastException ex) { + result = path2.getPath().toString().compareTo(path1.getPath().toString()); + } + } + return multiplier * result; + } +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/cdc19e40/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/ScriptCondition.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/ScriptCondition.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/ScriptCondition.java index 1abb792..9d728c0 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/ScriptCondition.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/ScriptCondition.java @@ -1,118 +1,120 @@ -/* - * 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.appender.rolling.action; - -import java.nio.file.Path; -import java.util.List; -import java.util.Objects; - -import javax.script.SimpleBindings; - -import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.core.config.Configuration; -import org.apache.logging.log4j.core.config.plugins.Plugin; -import org.apache.logging.log4j.core.config.plugins.PluginConfiguration; -import org.apache.logging.log4j.core.config.plugins.PluginElement; -import org.apache.logging.log4j.core.config.plugins.PluginFactory; -import org.apache.logging.log4j.core.script.AbstractScript; -import org.apache.logging.log4j.core.script.ScriptRef; -import org.apache.logging.log4j.status.StatusLogger; - -/** - * A condition of the {@link DeleteAction} where a user-provided script selects the files to delete from a provided - * list. The specified script may be a {@link Script}, a {@link ScriptFile} or a {@link ScriptRef}. - * - * @see #createCondition(AbstractScript, Configuration) - */ -@Plugin(name = "ScriptCondition", category = "Core", printObject = true) -public class ScriptCondition { - private static Logger LOGGER = StatusLogger.getLogger(); - - private final AbstractScript script; - private final Configuration configuration; - - /** - * Constructs a new ScriptCondition. - * - * @param script the script that can select files to delete - * @param configuration configuration containing the StrSubstitutor passed to the script - */ - public ScriptCondition(final AbstractScript script, final Configuration configuration) { - this.script = Objects.requireNonNull(script, "script"); - this.configuration = Objects.requireNonNull(configuration, "configuration"); - if (!(script instanceof ScriptRef)) { - configuration.getScriptManager().addScript(script); - } - } - - /** - * Executes the script - * - * @param baseDir - * @param candidates - * @return - */ - @SuppressWarnings("unchecked") - public List<PathWithAttributes> selectFilesToDelete(final Path basePath, final List<PathWithAttributes> candidates) { - final SimpleBindings bindings = new SimpleBindings(); - bindings.put("basePath", basePath); - bindings.put("pathList", candidates); - bindings.putAll(configuration.getProperties()); - bindings.put("configuration", configuration); - bindings.put("substitutor", configuration.getStrSubstitutor()); - bindings.put("statusLogger", LOGGER); - final Object object = configuration.getScriptManager().execute(script.getName(), bindings); - return (List<PathWithAttributes>) object; - } - - /** - * Creates the ScriptCondition. - * - * @param script The script to run. This may be a {@link Script}, a {@link ScriptFile} or a {@link ScriptRef}. The - * script must return a {@code List<PathWithAttributes>}. When the script is executed, it is provided the - * following bindings: - * <ul> - * <li>basePath - the directory from where the {@link DeleteAction Delete} action started scanning for - * files to delete. Can be used to relativize the paths in the pathList.</li> - * <li>pathList - a {@code java.util.List} containing {@link PathWithAttribute} objects. (The script is - * free to modify and return this list.)</li> - * <li>substitutor - a {@link StrSubstitutor} that can be used to look up variables embedded in the base - * dir or other properties - * <li>statusLogger - the {@link StatusLogger} that can be used to log events during script execution - * <li>any properties declared in the configuration</li> - * </ul> - * @param configuration the configuration - * @return A ScriptCondition. - */ - @PluginFactory - public static ScriptCondition createCondition(@PluginElement("Script") final AbstractScript script, - @PluginConfiguration final Configuration configuration) { - - if (script == null) { - LOGGER.error("A Script, ScriptFile or ScriptRef element must be provided for this ScriptCondition"); - return null; - } - if (script instanceof ScriptRef) { - if (configuration.getScriptManager().getScript(script.getName()) == null) { - LOGGER.error("ScriptCondition: No script with name {} has been declared.", script.getName()); - return null; - } - } - return new ScriptCondition(script, configuration); - } -} +/* + * 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.appender.rolling.action; + +import java.nio.file.Path; +import java.util.List; +import java.util.Objects; + +import javax.script.SimpleBindings; + +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.core.Core; +import org.apache.logging.log4j.core.config.Configuration; +import org.apache.logging.log4j.core.config.plugins.Plugin; +import org.apache.logging.log4j.core.config.plugins.PluginConfiguration; +import org.apache.logging.log4j.core.config.plugins.PluginElement; +import org.apache.logging.log4j.core.config.plugins.PluginFactory; +import org.apache.logging.log4j.core.script.AbstractScript; +import org.apache.logging.log4j.core.script.ScriptFile; +import org.apache.logging.log4j.core.script.ScriptRef; +import org.apache.logging.log4j.status.StatusLogger; + +/** + * A condition of the {@link DeleteAction} where a user-provided script selects the files to delete from a provided + * list. The specified script may be a {@link Script}, a {@link ScriptFile} or a {@link ScriptRef}. + * + * @see #createCondition(AbstractScript, Configuration) + */ +@Plugin(name = "ScriptCondition", category = Core.CATEGORY_NAME, printObject = true) +public class ScriptCondition { + private static Logger LOGGER = StatusLogger.getLogger(); + + private final AbstractScript script; + private final Configuration configuration; + + /** + * Constructs a new ScriptCondition. + * + * @param script the script that can select files to delete + * @param configuration configuration containing the StrSubstitutor passed to the script + */ + public ScriptCondition(final AbstractScript script, final Configuration configuration) { + this.script = Objects.requireNonNull(script, "script"); + this.configuration = Objects.requireNonNull(configuration, "configuration"); + if (!(script instanceof ScriptRef)) { + configuration.getScriptManager().addScript(script); + } + } + + /** + * Executes the script + * + * @param baseDir + * @param candidates + * @return + */ + @SuppressWarnings("unchecked") + public List<PathWithAttributes> selectFilesToDelete(final Path basePath, final List<PathWithAttributes> candidates) { + final SimpleBindings bindings = new SimpleBindings(); + bindings.put("basePath", basePath); + bindings.put("pathList", candidates); + bindings.putAll(configuration.getProperties()); + bindings.put("configuration", configuration); + bindings.put("substitutor", configuration.getStrSubstitutor()); + bindings.put("statusLogger", LOGGER); + final Object object = configuration.getScriptManager().execute(script.getName(), bindings); + return (List<PathWithAttributes>) object; + } + + /** + * Creates the ScriptCondition. + * + * @param script The script to run. This may be a {@link Script}, a {@link ScriptFile} or a {@link ScriptRef}. The + * script must return a {@code List<PathWithAttributes>}. When the script is executed, it is provided the + * following bindings: + * <ul> + * <li>basePath - the directory from where the {@link DeleteAction Delete} action started scanning for + * files to delete. Can be used to relativize the paths in the pathList.</li> + * <li>pathList - a {@code java.util.List} containing {@link PathWithAttribute} objects. (The script is + * free to modify and return this list.)</li> + * <li>substitutor - a {@link StrSubstitutor} that can be used to look up variables embedded in the base + * dir or other properties + * <li>statusLogger - the {@link StatusLogger} that can be used to log events during script execution + * <li>any properties declared in the configuration</li> + * </ul> + * @param configuration the configuration + * @return A ScriptCondition. + */ + @PluginFactory + public static ScriptCondition createCondition(@PluginElement("Script") final AbstractScript script, + @PluginConfiguration final Configuration configuration) { + + if (script == null) { + LOGGER.error("A Script, ScriptFile or ScriptRef element must be provided for this ScriptCondition"); + return null; + } + if (script instanceof ScriptRef) { + if (configuration.getScriptManager().getScript(script.getName()) == null) { + LOGGER.error("ScriptCondition: No script with name {} has been declared.", script.getName()); + return null; + } + } + return new ScriptCondition(script, configuration); + } +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/cdc19e40/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/routing/IdlePurgePolicy.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/routing/IdlePurgePolicy.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/routing/IdlePurgePolicy.java index 40898ac..e892f66 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/routing/IdlePurgePolicy.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/routing/IdlePurgePolicy.java @@ -23,6 +23,7 @@ import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; import org.apache.logging.log4j.core.AbstractLifeCycle; +import org.apache.logging.log4j.core.Core; import org.apache.logging.log4j.core.LogEvent; import org.apache.logging.log4j.core.config.Configuration; import org.apache.logging.log4j.core.config.ConfigurationScheduler; @@ -35,7 +36,7 @@ import org.apache.logging.log4j.core.config.plugins.PluginFactory; /** * Policy is purging appenders that were not in use specified time in minutes */ -@Plugin(name = "IdlePurgePolicy", category = "Core", printObject = true) +@Plugin(name = "IdlePurgePolicy", category = Core.CATEGORY_NAME, printObject = true) @Scheduled public class IdlePurgePolicy extends AbstractLifeCycle implements PurgePolicy, Runnable { http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/cdc19e40/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/routing/Route.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/routing/Route.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/routing/Route.java index b1f5ae4..1a92b66 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/routing/Route.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/routing/Route.java @@ -17,6 +17,7 @@ package org.apache.logging.log4j.core.appender.routing; import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.core.Core; import org.apache.logging.log4j.core.config.Node; import org.apache.logging.log4j.core.config.plugins.Plugin; import org.apache.logging.log4j.core.config.plugins.PluginAttribute; @@ -27,7 +28,7 @@ import org.apache.logging.log4j.status.StatusLogger; /** * A Route to an appender. */ -@Plugin(name = "Route", category = "Core", printObject = true, deferChildren = true) +@Plugin(name = "Route", category = Core.CATEGORY_NAME, printObject = true, deferChildren = true) public final class Route { private static final Logger LOGGER = StatusLogger.getLogger(); http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/cdc19e40/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/routing/Routes.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/routing/Routes.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/routing/Routes.java index 6fb2487..e179ad7 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/routing/Routes.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/routing/Routes.java @@ -24,6 +24,7 @@ import java.util.concurrent.ConcurrentMap; import javax.script.Bindings; import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.core.Core; import org.apache.logging.log4j.core.LogEvent; import org.apache.logging.log4j.core.config.Configuration; import org.apache.logging.log4j.core.config.plugins.Plugin; @@ -39,7 +40,7 @@ import org.apache.logging.log4j.status.StatusLogger; /** * Contains the individual Route elements. */ -@Plugin(name = "Routes", category = "Core", printObject = true) +@Plugin(name = "Routes", category = Core.CATEGORY_NAME, printObject = true) public final class Routes { private static final String LOG_EVENT_KEY = "logEvent"; http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/cdc19e40/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/routing/RoutingAppender.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/routing/RoutingAppender.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/routing/RoutingAppender.java index adc1543..9e9e13e 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/routing/RoutingAppender.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/routing/RoutingAppender.java @@ -26,6 +26,7 @@ import java.util.concurrent.TimeUnit; import javax.script.Bindings; import org.apache.logging.log4j.core.Appender; +import org.apache.logging.log4j.core.Core; import org.apache.logging.log4j.core.Filter; import org.apache.logging.log4j.core.LifeCycle2; import org.apache.logging.log4j.core.LogEvent; @@ -50,7 +51,7 @@ import org.apache.logging.log4j.core.util.Booleans; * the form "$${[key:]token}". The pattern will be resolved each time the Appender is called using * the built in StrSubstitutor and the StrLookup plugin that matches the specified key. */ -@Plugin(name = "Routing", category = "Core", elementType = Appender.ELEMENT_TYPE, printObject = true) +@Plugin(name = "Routing", category = Core.CATEGORY_NAME, elementType = Appender.ELEMENT_TYPE, printObject = true) public final class RoutingAppender extends AbstractAppender { public static final String STATIC_VARIABLES_KEY = "staticVariables"; http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/cdc19e40/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfig.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfig.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfig.java index 170b0da..f15dcad 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfig.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfig.java @@ -22,6 +22,7 @@ import java.util.concurrent.TimeUnit; import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.core.Core; import org.apache.logging.log4j.core.Filter; import org.apache.logging.log4j.core.LogEvent; import org.apache.logging.log4j.core.config.AppenderRef; @@ -197,7 +198,7 @@ public class AsyncLoggerConfig extends LoggerConfig { /** * An asynchronous root Logger. */ - @Plugin(name = "asyncRoot", category = "Core", printObject = true) + @Plugin(name = "asyncRoot", category = Core.CATEGORY_NAME, printObject = true) public static class RootLogger extends LoggerConfig { @PluginFactory http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/cdc19e40/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AppendersPlugin.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AppendersPlugin.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AppendersPlugin.java index 3545d2c..03f5e06 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AppendersPlugin.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AppendersPlugin.java @@ -20,6 +20,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import org.apache.logging.log4j.core.Appender; +import org.apache.logging.log4j.core.Core; import org.apache.logging.log4j.core.config.plugins.Plugin; import org.apache.logging.log4j.core.config.plugins.PluginElement; import org.apache.logging.log4j.core.config.plugins.PluginFactory; @@ -27,7 +28,7 @@ import org.apache.logging.log4j.core.config.plugins.PluginFactory; /** * An Appender container. */ -@Plugin(name = "appenders", category = "Core") +@Plugin(name = "appenders", category = Core.CATEGORY_NAME) public final class AppendersPlugin { private AppendersPlugin() { http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/cdc19e40/log4j-core/src/main/java/org/apache/logging/log4j/core/config/CustomLevelConfig.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/CustomLevelConfig.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/CustomLevelConfig.java index e7e00d1..ca6bd9b 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/CustomLevelConfig.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/CustomLevelConfig.java @@ -19,6 +19,7 @@ package org.apache.logging.log4j.core.config; import java.util.Objects; import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.core.Core; import org.apache.logging.log4j.core.config.plugins.Plugin; import org.apache.logging.log4j.core.config.plugins.PluginAttribute; import org.apache.logging.log4j.core.config.plugins.PluginFactory; @@ -27,7 +28,7 @@ import org.apache.logging.log4j.status.StatusLogger; /** * Descriptor of a custom Level object that is created via configuration. */ -@Plugin(name = "CustomLevel", category = "Core", printObject = true) +@Plugin(name = "CustomLevel", category = Core.CATEGORY_NAME, printObject = true) public final class CustomLevelConfig { private final String levelName; http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/cdc19e40/log4j-core/src/main/java/org/apache/logging/log4j/core/config/CustomLevels.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/CustomLevels.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/CustomLevels.java index 59abd57..0b43858 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/CustomLevels.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/CustomLevels.java @@ -21,6 +21,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import org.apache.logging.log4j.core.Core; import org.apache.logging.log4j.core.config.plugins.Plugin; import org.apache.logging.log4j.core.config.plugins.PluginElement; import org.apache.logging.log4j.core.config.plugins.PluginFactory; @@ -28,7 +29,7 @@ import org.apache.logging.log4j.core.config.plugins.PluginFactory; /** * Container for CustomLevelConfig objects. */ -@Plugin(name = "CustomLevels", category = "Core", printObject = true) +@Plugin(name = "CustomLevels", category = Core.CATEGORY_NAME, printObject = true) public final class CustomLevels { private final List<CustomLevelConfig> customLevels; http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/cdc19e40/log4j-core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java index 98b586f..6c44014 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java @@ -27,6 +27,7 @@ import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Marker; import org.apache.logging.log4j.core.Appender; +import org.apache.logging.log4j.core.Core; import org.apache.logging.log4j.core.Filter; import org.apache.logging.log4j.core.LogEvent; import org.apache.logging.log4j.core.async.AsyncLoggerContextSelector; @@ -536,7 +537,7 @@ public class LoggerConfig extends AbstractFilterable { /** * The root Logger. */ - @Plugin(name = ROOT, category = "Core", printObject = true) + @Plugin(name = ROOT, category = Core.CATEGORY_NAME, printObject = true) public static class RootLogger extends LoggerConfig { @PluginFactory http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/cdc19e40/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ScriptsPlugin.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ScriptsPlugin.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ScriptsPlugin.java index bd01dbe..4c3ae89 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ScriptsPlugin.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ScriptsPlugin.java @@ -16,6 +16,7 @@ */ package org.apache.logging.log4j.core.config; +import org.apache.logging.log4j.core.Core; import org.apache.logging.log4j.core.config.plugins.Plugin; import org.apache.logging.log4j.core.config.plugins.PluginElement; import org.apache.logging.log4j.core.config.plugins.PluginFactory; @@ -24,7 +25,7 @@ import org.apache.logging.log4j.core.script.AbstractScript; /** * A container of Scripts. */ -@Plugin(name = "scripts", category = "Core") +@Plugin(name = "scripts", category = Core.CATEGORY_NAME) public final class ScriptsPlugin { private ScriptsPlugin() { http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/cdc19e40/log4j-core/src/main/java/org/apache/logging/log4j/core/net/MulticastDnsAdvertiser.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/MulticastDnsAdvertiser.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/MulticastDnsAdvertiser.java index a1fb7de..3d610bf 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/MulticastDnsAdvertiser.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/MulticastDnsAdvertiser.java @@ -23,6 +23,7 @@ import java.util.Hashtable; import java.util.Map; import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.core.Core; import org.apache.logging.log4j.core.config.plugins.Plugin; import org.apache.logging.log4j.core.util.Integers; import org.apache.logging.log4j.status.StatusLogger; @@ -35,7 +36,7 @@ import org.apache.logging.log4j.util.LoaderUtil; * will be removed prior to advertisement. * */ -@Plugin(name = "multicastdns", category = "Core", elementType = "advertiser", printObject = false) +@Plugin(name = "multicastdns", category = Core.CATEGORY_NAME, elementType = "advertiser", printObject = false) public class MulticastDnsAdvertiser implements Advertiser { /** * Status logger. http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/cdc19e40/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/KeyStoreConfiguration.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/KeyStoreConfiguration.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/KeyStoreConfiguration.java index 2c8ed7a..c168e7e 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/KeyStoreConfiguration.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/KeyStoreConfiguration.java @@ -22,6 +22,7 @@ import java.security.UnrecoverableKeyException; import javax.net.ssl.KeyManagerFactory; +import org.apache.logging.log4j.core.Core; import org.apache.logging.log4j.core.config.plugins.Plugin; import org.apache.logging.log4j.core.config.plugins.PluginAttribute; import org.apache.logging.log4j.core.config.plugins.PluginFactory; @@ -29,7 +30,7 @@ import org.apache.logging.log4j.core.config.plugins.PluginFactory; /** * Configuration of the KeyStore */ -@Plugin(name = "KeyStore", category = "Core", printObject = true) +@Plugin(name = "KeyStore", category = Core.CATEGORY_NAME, printObject = true) public class KeyStoreConfiguration extends AbstractKeyStoreConfiguration { private final String keyManagerFactoryAlgorithm; http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/cdc19e40/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/SslConfiguration.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/SslConfiguration.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/SslConfiguration.java index 267cc24..8632007 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/SslConfiguration.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/SslConfiguration.java @@ -29,6 +29,7 @@ import javax.net.ssl.SSLSocketFactory; import javax.net.ssl.TrustManager; import javax.net.ssl.TrustManagerFactory; +import org.apache.logging.log4j.core.Core; import org.apache.logging.log4j.core.config.plugins.Plugin; import org.apache.logging.log4j.core.config.plugins.PluginAttribute; import org.apache.logging.log4j.core.config.plugins.PluginElement; @@ -38,7 +39,7 @@ import org.apache.logging.log4j.status.StatusLogger; /** * SSL Configuration */ -@Plugin(name = "Ssl", category = "Core", printObject = true) +@Plugin(name = "Ssl", category = Core.CATEGORY_NAME, printObject = true) public class SslConfiguration { private static final StatusLogger LOGGER = StatusLogger.getLogger(); private final KeyStoreConfiguration keyStoreConfig; http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/cdc19e40/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/TrustStoreConfiguration.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/TrustStoreConfiguration.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/TrustStoreConfiguration.java index 11f045f..5164e23 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/TrustStoreConfiguration.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/TrustStoreConfiguration.java @@ -21,6 +21,7 @@ import java.security.NoSuchAlgorithmException; import javax.net.ssl.TrustManagerFactory; +import org.apache.logging.log4j.core.Core; import org.apache.logging.log4j.core.config.plugins.Plugin; import org.apache.logging.log4j.core.config.plugins.PluginAttribute; import org.apache.logging.log4j.core.config.plugins.PluginFactory; @@ -28,7 +29,7 @@ import org.apache.logging.log4j.core.config.plugins.PluginFactory; /** * Configuration of the TrustStore */ -@Plugin(name = "TrustStore", category = "Core", printObject = true) +@Plugin(name = "TrustStore", category = Core.CATEGORY_NAME, printObject = true) public class TrustStoreConfiguration extends AbstractKeyStoreConfiguration { private final String trustManagerFactoryAlgorithm; http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/cdc19e40/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/RegexReplacement.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/RegexReplacement.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/RegexReplacement.java index 3ffc63c..47ce355 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/RegexReplacement.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/RegexReplacement.java @@ -19,6 +19,7 @@ package org.apache.logging.log4j.core.pattern; import java.util.regex.Pattern; import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.core.Core; import org.apache.logging.log4j.core.config.plugins.Plugin; import org.apache.logging.log4j.core.config.plugins.PluginAttribute; import org.apache.logging.log4j.core.config.plugins.PluginFactory; @@ -27,7 +28,7 @@ import org.apache.logging.log4j.status.StatusLogger; /** * Replace tokens in the LogEvent message. */ -@Plugin(name = "replace", category = "Core", printObject = true) +@Plugin(name = "replace", category = Core.CATEGORY_NAME, printObject = true) public final class RegexReplacement { private static final Logger LOGGER = StatusLogger.getLogger(); http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/cdc19e40/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/HangingAppender.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/HangingAppender.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/HangingAppender.java index 31891d3..0e48767 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/HangingAppender.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/HangingAppender.java @@ -29,7 +29,7 @@ import org.apache.logging.log4j.core.config.plugins.PluginElement; import org.apache.logging.log4j.core.config.plugins.PluginFactory; import org.apache.logging.log4j.core.config.plugins.validation.constraints.Required; -@Plugin(name = "Hanging", category = "Core", elementType = Appender.ELEMENT_TYPE, printObject = true) +@Plugin(name = "Hanging", category = Core.CATEGORY_NAME, elementType = Appender.ELEMENT_TYPE, printObject = true) public class HangingAppender extends AbstractAppender { private static final long serialVersionUID = 1L; http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/cdc19e40/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rewrite/TestRewritePolicy.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rewrite/TestRewritePolicy.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rewrite/TestRewritePolicy.java index 99dc33c..38d1123 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rewrite/TestRewritePolicy.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rewrite/TestRewritePolicy.java @@ -24,7 +24,7 @@ import org.apache.logging.log4j.core.impl.Log4jLogEvent; /** * */ -@Plugin(name = "TestRewritePolicy", category = "Core", elementType = "rewritePolicy", printObject = true) +@Plugin(name = "TestRewritePolicy", category = Core.CATEGORY_NAME, elementType = "rewritePolicy", printObject = true) public class TestRewritePolicy implements RewritePolicy { @Override http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/cdc19e40/log4j-core/src/test/java/org/apache/logging/log4j/core/config/InMemoryAdvertiser.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/InMemoryAdvertiser.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/InMemoryAdvertiser.java index 81d9676..8273b2c 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/InMemoryAdvertiser.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/InMemoryAdvertiser.java @@ -22,7 +22,7 @@ import java.util.Map; import org.apache.logging.log4j.core.config.plugins.Plugin; import org.apache.logging.log4j.core.net.Advertiser; -@Plugin(name = "memory", category = "Core", elementType = "advertiser", printObject = false) +@Plugin(name = "memory", category = Core.CATEGORY_NAME, elementType = "advertiser", printObject = false) public class InMemoryAdvertiser implements Advertiser { private static Map<Object, Map<String, String>> properties = new HashMap<>(); http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/cdc19e40/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/ListAppender.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/ListAppender.java b/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/ListAppender.java index 05aa46e..f006c5d 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/ListAppender.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/ListAppender.java @@ -47,7 +47,7 @@ import org.apache.logging.log4j.core.layout.SerializedLayout; * * @see org.apache.logging.log4j.junit.LoggerContextRule#getListAppender(String) ILC.getListAppender */ -@Plugin(name = "List", category = "Core", elementType = Appender.ELEMENT_TYPE, printObject = true) +@Plugin(name = "List", category = Core.CATEGORY_NAME, elementType = Appender.ELEMENT_TYPE, printObject = true) public class ListAppender extends AbstractAppender { // Use CopyOnWriteArrayList? http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/cdc19e40/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/UsesLoggingAppender.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/UsesLoggingAppender.java b/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/UsesLoggingAppender.java index 44a264c..72094a2 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/UsesLoggingAppender.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/UsesLoggingAppender.java @@ -31,7 +31,7 @@ import org.apache.logging.log4j.test.SomethingThatUsesLogging; /** * */ -@Plugin(name = "UsesLoggingAppender", category = "Core", elementType = Appender.ELEMENT_TYPE, printObject = true) +@Plugin(name = "UsesLoggingAppender", category = Core.CATEGORY_NAME, elementType = Appender.ELEMENT_TYPE, printObject = true) public final class UsesLoggingAppender extends AbstractAppender { private final SomethingThatUsesLogging thing; http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/cdc19e40/log4j-core/src/test/java/org/apache/logging/log4j/test/layout/BasicLayout.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/test/layout/BasicLayout.java b/log4j-core/src/test/java/org/apache/logging/log4j/test/layout/BasicLayout.java index bc20a7e..79241e6 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/test/layout/BasicLayout.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/test/layout/BasicLayout.java @@ -28,7 +28,7 @@ import org.apache.logging.log4j.util.Strings; /** * */ -@Plugin(name = "BasicLayout", category = "Core", elementType = "layout", printObject = true) +@Plugin(name = "BasicLayout", category = Core.CATEGORY_NAME, elementType = "layout", printObject = true) public class BasicLayout extends AbstractStringLayout { private static final String HEADER = "Header" + Strings.LINE_SEPARATOR;
