You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by gg...@apache.org on 2016/04/18 02:26:37 UTC
[1/8] logging-log4j2 git commit: Statement unnecessarily nested.
Repository: logging-log4j2
Updated Branches:
refs/heads/master 9a563a63f -> d3e571f37
Statement unnecessarily nested.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/a7f60a25
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/a7f60a25
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/a7f60a25
Branch: refs/heads/master
Commit: a7f60a25a89126cd183ed5181ab526fcfbd213c2
Parents: 9a563a6
Author: ggregory <gg...@apache.org>
Authored: Sun Apr 17 16:55:32 2016 -0700
Committer: ggregory <gg...@apache.org>
Committed: Sun Apr 17 16:55:32 2016 -0700
----------------------------------------------------------------------
.../appender/rolling/action/DeleteAction.java | 432 +++++++++----------
.../logging/log4j/core/impl/Log4jLogEvent.java | 3 +-
.../logging/log4j/core/layout/GelfLayout.java | 9 +-
.../core/pattern/DatePatternConverter.java | 3 +-
4 files changed, 220 insertions(+), 227 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/a7f60a25/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/DeleteAction.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/DeleteAction.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/DeleteAction.java
index c2c385f..8176470 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/DeleteAction.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/DeleteAction.java
@@ -1,218 +1,214 @@
-/*
- * 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.IOException;
-import java.nio.file.FileVisitor;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.util.List;
-import java.util.Objects;
-
-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.PluginAttribute;
-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.lookup.StrSubstitutor;
-
-/**
- * Rollover or scheduled action for deleting old log files that are accepted by the specified PathFilters.
- */
-@Plugin(name = "Delete", category = "Core", printObject = true)
-public class DeleteAction extends AbstractPathAction {
-
- private final PathSorter pathSorter;
- private final boolean testMode;
- private final ScriptCondition scriptCondition;
-
- /**
- * Creates a new DeleteAction that starts scanning for files to delete from the specified base path.
- *
- * @param basePath base path from where to start scanning for files to delete.
- * @param followSymbolicLinks whether to follow symbolic links. Default is false.
- * @param maxDepth The maxDepth parameter is the maximum number of levels of directories to visit. A value of 0
- * means that only the starting file is visited, unless denied by the security manager. A value of
- * MAX_VALUE may be used to indicate that all levels should be visited.
- * @param testMode if true, files are not deleted but instead a message is printed to the <a
- * href="http://logging.apache.org/log4j/2.x/manual/configuration.html#StatusMessages">status logger</a>
- * at INFO level. Users can use this to do a dry run to test if their configuration works as expected.
- * @param sorter sorts
- * @param pathConditions an array of path filters (if more than one, they all need to accept a path before it is
- * deleted).
- * @param scriptCondition
- */
- DeleteAction(final String basePath, final boolean followSymbolicLinks, final int maxDepth, final boolean testMode,
- final PathSorter sorter, final PathCondition[] pathConditions, final ScriptCondition scriptCondition,
- final StrSubstitutor subst) {
- super(basePath, followSymbolicLinks, maxDepth, pathConditions, subst);
- this.testMode = testMode;
- this.pathSorter = Objects.requireNonNull(sorter, "sorter");
- this.scriptCondition = scriptCondition;
- if (scriptCondition == null && (pathConditions == null || pathConditions.length == 0)) {
- LOGGER.error("Missing Delete conditions: unconditional Delete not supported");
- throw new IllegalArgumentException("Unconditional Delete not supported");
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.logging.log4j.core.appender.rolling.action.AbstractPathAction#execute()
- */
- @Override
- public boolean execute() throws IOException {
- if (scriptCondition != null) {
- return executeScript();
- } else {
- return super.execute();
- }
- }
-
- private boolean executeScript() throws IOException {
- final List<PathWithAttributes> selectedForDeletion = callScript();
- if (selectedForDeletion == null) {
- LOGGER.trace("Script returned null list (no files to delete)");
- return true;
- }
- deleteSelectedFiles(selectedForDeletion);
- return true;
- }
-
- private List<PathWithAttributes> callScript() throws IOException {
- final List<PathWithAttributes> sortedPaths = getSortedPaths();
- trace("Sorted paths:", sortedPaths);
- final List<PathWithAttributes> result = scriptCondition.selectFilesToDelete(getBasePath(), sortedPaths);
- return result;
- }
-
- private void deleteSelectedFiles(final List<PathWithAttributes> selectedForDeletion) throws IOException {
- trace("Paths the script selected for deletion:", selectedForDeletion);
- for (final PathWithAttributes pathWithAttributes : selectedForDeletion) {
- final Path path = pathWithAttributes == null ? null : pathWithAttributes.getPath();
- if (isTestMode()) {
- LOGGER.info("Deleting {} (TEST MODE: file not actually deleted)", path);
- } else {
- delete(path);
- }
- }
- }
-
- /**
- * Deletes the specified file.
- *
- * @param path the file to delete
- * @throws IOException if a problem occurred deleting the file
- */
- protected void delete(final Path path) throws IOException {
- LOGGER.trace("Deleting {}", path);
- Files.deleteIfExists(path);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.logging.log4j.core.appender.rolling.action.AbstractPathAction#execute(FileVisitor)
- */
- @Override
- public boolean execute(final FileVisitor<Path> visitor) throws IOException {
- final List<PathWithAttributes> sortedPaths = getSortedPaths();
- trace("Sorted paths:", sortedPaths);
-
- for (PathWithAttributes element : sortedPaths) {
- try {
- visitor.visitFile(element.getPath(), element.getAttributes());
- } catch (final IOException ioex) {
- LOGGER.error("Error in post-rollover Delete when visiting {}", element.getPath(), ioex);
- visitor.visitFileFailed(element.getPath(), ioex);
- }
- }
- // TODO return (visitor.success || ignoreProcessingFailure)
- return true; // do not abort rollover even if processing failed
- }
-
- private void trace(final String label, final List<PathWithAttributes> sortedPaths) {
- LOGGER.trace(label);
- for (final PathWithAttributes pathWithAttributes : sortedPaths) {
- LOGGER.trace(pathWithAttributes);
- }
- }
-
- /**
- * Returns a sorted list of all files up to maxDepth under the basePath.
- *
- * @return a sorted list of files
- * @throws IOException
- */
- List<PathWithAttributes> getSortedPaths() throws IOException {
- final SortingVisitor sort = new SortingVisitor(pathSorter);
- super.execute(sort);
- final List<PathWithAttributes> sortedPaths = sort.getSortedPaths();
- return sortedPaths;
- }
-
- /**
- * Returns {@code true} if files are not deleted even when all conditions accept a path, {@code false} otherwise.
- *
- * @return {@code true} if files are not deleted even when all conditions accept a path, {@code false} otherwise
- */
- public boolean isTestMode() {
- return testMode;
- }
-
- @Override
- protected FileVisitor<Path> createFileVisitor(final Path visitorBaseDir, final List<PathCondition> conditions) {
- return new DeletingVisitor(visitorBaseDir, conditions, testMode);
- }
-
- /**
- * Create a DeleteAction.
- *
- * @param basePath base path from where to start scanning for files to delete.
- * @param followLinks whether to follow symbolic links. Default is false.
- * @param maxDepth The maxDepth parameter is the maximum number of levels of directories to visit. A value of 0
- * means that only the starting file is visited, unless denied by the security manager. A value of
- * MAX_VALUE may be used to indicate that all levels should be visited.
- * @param testMode if true, files are not deleted but instead a message is printed to the <a
- * href="http://logging.apache.org/log4j/2.x/manual/configuration.html#StatusMessages">status logger</a>
- * at INFO level. Users can use this to do a dry run to test if their configuration works as expected.
- * Default is false.
- * @param PathSorter a plugin implementing the {@link PathSorter} interface
- * @param PathConditions an array of path conditions (if more than one, they all need to accept a path before it is
- * deleted).
- * @param config The Configuration.
- * @return A DeleteAction.
- */
- @PluginFactory
- public static DeleteAction createDeleteAction(
- // @formatter:off
- @PluginAttribute("basePath") final String basePath, //
- @PluginAttribute(value = "followLinks", defaultBoolean = false) final boolean followLinks,
- @PluginAttribute(value = "maxDepth", defaultInt = 1) final int maxDepth,
- @PluginAttribute(value = "testMode", defaultBoolean = false) final boolean testMode,
- @PluginElement("PathSorter") final PathSorter sorterParameter,
- @PluginElement("PathConditions") final PathCondition[] pathConditions,
- @PluginElement("ScriptCondition") final ScriptCondition scriptCondition,
- @PluginConfiguration final Configuration config) {
- // @formatter:on
- final PathSorter sorter = sorterParameter == null ? new PathSortByModificationTime(true) : sorterParameter;
- return new DeleteAction(basePath, followLinks, maxDepth, testMode, sorter, pathConditions, scriptCondition,
- config.getStrSubstitutor());
- }
-}
+/*
+ * 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.IOException;
+import java.nio.file.FileVisitor;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.List;
+import java.util.Objects;
+
+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.PluginAttribute;
+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.lookup.StrSubstitutor;
+
+/**
+ * Rollover or scheduled action for deleting old log files that are accepted by the specified PathFilters.
+ */
+@Plugin(name = "Delete", category = "Core", printObject = true)
+public class DeleteAction extends AbstractPathAction {
+
+ private final PathSorter pathSorter;
+ private final boolean testMode;
+ private final ScriptCondition scriptCondition;
+
+ /**
+ * Creates a new DeleteAction that starts scanning for files to delete from the specified base path.
+ *
+ * @param basePath base path from where to start scanning for files to delete.
+ * @param followSymbolicLinks whether to follow symbolic links. Default is false.
+ * @param maxDepth The maxDepth parameter is the maximum number of levels of directories to visit. A value of 0
+ * means that only the starting file is visited, unless denied by the security manager. A value of
+ * MAX_VALUE may be used to indicate that all levels should be visited.
+ * @param testMode if true, files are not deleted but instead a message is printed to the <a
+ * href="http://logging.apache.org/log4j/2.x/manual/configuration.html#StatusMessages">status logger</a>
+ * at INFO level. Users can use this to do a dry run to test if their configuration works as expected.
+ * @param sorter sorts
+ * @param pathConditions an array of path filters (if more than one, they all need to accept a path before it is
+ * deleted).
+ * @param scriptCondition
+ */
+ DeleteAction(final String basePath, final boolean followSymbolicLinks, final int maxDepth, final boolean testMode,
+ final PathSorter sorter, final PathCondition[] pathConditions, final ScriptCondition scriptCondition,
+ final StrSubstitutor subst) {
+ super(basePath, followSymbolicLinks, maxDepth, pathConditions, subst);
+ this.testMode = testMode;
+ this.pathSorter = Objects.requireNonNull(sorter, "sorter");
+ this.scriptCondition = scriptCondition;
+ if (scriptCondition == null && (pathConditions == null || pathConditions.length == 0)) {
+ LOGGER.error("Missing Delete conditions: unconditional Delete not supported");
+ throw new IllegalArgumentException("Unconditional Delete not supported");
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.logging.log4j.core.appender.rolling.action.AbstractPathAction#execute()
+ */
+ @Override
+ public boolean execute() throws IOException {
+ return scriptCondition != null ? executeScript() : super.execute();
+ }
+
+ private boolean executeScript() throws IOException {
+ final List<PathWithAttributes> selectedForDeletion = callScript();
+ if (selectedForDeletion == null) {
+ LOGGER.trace("Script returned null list (no files to delete)");
+ return true;
+ }
+ deleteSelectedFiles(selectedForDeletion);
+ return true;
+ }
+
+ private List<PathWithAttributes> callScript() throws IOException {
+ final List<PathWithAttributes> sortedPaths = getSortedPaths();
+ trace("Sorted paths:", sortedPaths);
+ final List<PathWithAttributes> result = scriptCondition.selectFilesToDelete(getBasePath(), sortedPaths);
+ return result;
+ }
+
+ private void deleteSelectedFiles(final List<PathWithAttributes> selectedForDeletion) throws IOException {
+ trace("Paths the script selected for deletion:", selectedForDeletion);
+ for (final PathWithAttributes pathWithAttributes : selectedForDeletion) {
+ final Path path = pathWithAttributes == null ? null : pathWithAttributes.getPath();
+ if (isTestMode()) {
+ LOGGER.info("Deleting {} (TEST MODE: file not actually deleted)", path);
+ } else {
+ delete(path);
+ }
+ }
+ }
+
+ /**
+ * Deletes the specified file.
+ *
+ * @param path the file to delete
+ * @throws IOException if a problem occurred deleting the file
+ */
+ protected void delete(final Path path) throws IOException {
+ LOGGER.trace("Deleting {}", path);
+ Files.deleteIfExists(path);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.logging.log4j.core.appender.rolling.action.AbstractPathAction#execute(FileVisitor)
+ */
+ @Override
+ public boolean execute(final FileVisitor<Path> visitor) throws IOException {
+ final List<PathWithAttributes> sortedPaths = getSortedPaths();
+ trace("Sorted paths:", sortedPaths);
+
+ for (PathWithAttributes element : sortedPaths) {
+ try {
+ visitor.visitFile(element.getPath(), element.getAttributes());
+ } catch (final IOException ioex) {
+ LOGGER.error("Error in post-rollover Delete when visiting {}", element.getPath(), ioex);
+ visitor.visitFileFailed(element.getPath(), ioex);
+ }
+ }
+ // TODO return (visitor.success || ignoreProcessingFailure)
+ return true; // do not abort rollover even if processing failed
+ }
+
+ private void trace(final String label, final List<PathWithAttributes> sortedPaths) {
+ LOGGER.trace(label);
+ for (final PathWithAttributes pathWithAttributes : sortedPaths) {
+ LOGGER.trace(pathWithAttributes);
+ }
+ }
+
+ /**
+ * Returns a sorted list of all files up to maxDepth under the basePath.
+ *
+ * @return a sorted list of files
+ * @throws IOException
+ */
+ List<PathWithAttributes> getSortedPaths() throws IOException {
+ final SortingVisitor sort = new SortingVisitor(pathSorter);
+ super.execute(sort);
+ final List<PathWithAttributes> sortedPaths = sort.getSortedPaths();
+ return sortedPaths;
+ }
+
+ /**
+ * Returns {@code true} if files are not deleted even when all conditions accept a path, {@code false} otherwise.
+ *
+ * @return {@code true} if files are not deleted even when all conditions accept a path, {@code false} otherwise
+ */
+ public boolean isTestMode() {
+ return testMode;
+ }
+
+ @Override
+ protected FileVisitor<Path> createFileVisitor(final Path visitorBaseDir, final List<PathCondition> conditions) {
+ return new DeletingVisitor(visitorBaseDir, conditions, testMode);
+ }
+
+ /**
+ * Create a DeleteAction.
+ *
+ * @param basePath base path from where to start scanning for files to delete.
+ * @param followLinks whether to follow symbolic links. Default is false.
+ * @param maxDepth The maxDepth parameter is the maximum number of levels of directories to visit. A value of 0
+ * means that only the starting file is visited, unless denied by the security manager. A value of
+ * MAX_VALUE may be used to indicate that all levels should be visited.
+ * @param testMode if true, files are not deleted but instead a message is printed to the <a
+ * href="http://logging.apache.org/log4j/2.x/manual/configuration.html#StatusMessages">status logger</a>
+ * at INFO level. Users can use this to do a dry run to test if their configuration works as expected.
+ * Default is false.
+ * @param PathSorter a plugin implementing the {@link PathSorter} interface
+ * @param PathConditions an array of path conditions (if more than one, they all need to accept a path before it is
+ * deleted).
+ * @param config The Configuration.
+ * @return A DeleteAction.
+ */
+ @PluginFactory
+ public static DeleteAction createDeleteAction(
+ // @formatter:off
+ @PluginAttribute("basePath") final String basePath, //
+ @PluginAttribute(value = "followLinks", defaultBoolean = false) final boolean followLinks,
+ @PluginAttribute(value = "maxDepth", defaultInt = 1) final int maxDepth,
+ @PluginAttribute(value = "testMode", defaultBoolean = false) final boolean testMode,
+ @PluginElement("PathSorter") final PathSorter sorterParameter,
+ @PluginElement("PathConditions") final PathCondition[] pathConditions,
+ @PluginElement("ScriptCondition") final ScriptCondition scriptCondition,
+ @PluginConfiguration final Configuration config) {
+ // @formatter:on
+ final PathSorter sorter = sorterParameter == null ? new PathSortByModificationTime(true) : sorterParameter;
+ return new DeleteAction(basePath, followLinks, maxDepth, testMode, sorter, pathConditions, scriptCondition,
+ config.getStrSubstitutor());
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/a7f60a25/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/Log4jLogEvent.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/Log4jLogEvent.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/Log4jLogEvent.java
index c062259..26b35d3 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/Log4jLogEvent.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/Log4jLogEvent.java
@@ -638,9 +638,8 @@ public Log4jLogEvent(final String loggerName, final Marker marker, final String
if (event instanceof Log4jLogEvent) {
event.getThrownProxy(); // ensure ThrowableProxy is initialized
return new LogEventProxy((Log4jLogEvent) event, includeLocation);
- } else {
- return new LogEventProxy(event, includeLocation);
}
+ return new LogEventProxy(event, includeLocation);
}
public static Serializable serialize(final Log4jLogEvent event, final boolean includeLocation) {
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/a7f60a25/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/GelfLayout.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/GelfLayout.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/GelfLayout.java
index 788ce73..dfa07d5 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/GelfLayout.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/GelfLayout.java
@@ -254,12 +254,11 @@ public final class GelfLayout extends AbstractStringLayout {
static CharSequence formatTimestamp(final long timeMillis) {
if (timeMillis < 1000) {
return "0";
- } else {
- StringBuilder builder = getTimestampStringBuilder();
- builder.append(timeMillis);
- builder.insert(builder.length() - 3, '.');
- return builder;
}
+ StringBuilder builder = getTimestampStringBuilder();
+ builder.append(timeMillis);
+ builder.insert(builder.length() - 3, '.');
+ return builder;
}
private static final ThreadLocal<StringBuilder> timestampStringBuilder = new ThreadLocal<>();
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/a7f60a25/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/DatePatternConverter.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/DatePatternConverter.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/DatePatternConverter.java
index b837338..499f0d9 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/DatePatternConverter.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/DatePatternConverter.java
@@ -175,9 +175,8 @@ public final class DatePatternConverter extends LogEventPatternConverter impleme
final FixedDateFormat fixedDateFormat = FixedDateFormat.createIfSupported(options);
if (fixedDateFormat != null) {
return createFixedFormatter(fixedDateFormat);
- } else {
- return createNonFixedFormatter(options);
}
+ return createNonFixedFormatter(options);
}
/**
[6/8] logging-log4j2 git commit: Remove dead comment.
Posted by gg...@apache.org.
Remove dead comment.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/ce36b376
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/ce36b376
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/ce36b376
Branch: refs/heads/master
Commit: ce36b37661e45c89c861108b6442eb8249ec2248
Parents: 6b9955d
Author: ggregory <gg...@apache.org>
Authored: Sun Apr 17 17:13:17 2016 -0700
Committer: ggregory <gg...@apache.org>
Committed: Sun Apr 17 17:13:17 2016 -0700
----------------------------------------------------------------------
.../log4j/core/layout/CsvLogEventLayout.java | 213 +++++++++----------
1 file changed, 106 insertions(+), 107 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ce36b376/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/CsvLogEventLayout.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/CsvLogEventLayout.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/CsvLogEventLayout.java
index ef69f0f..12e0f3d 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/CsvLogEventLayout.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/CsvLogEventLayout.java
@@ -1,107 +1,106 @@
-/*
- * 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.layout;
-
-import java.io.IOException;
-import java.nio.charset.Charset;
-
-import org.apache.commons.csv.CSVFormat;
-import org.apache.commons.csv.CSVPrinter;
-import org.apache.commons.csv.QuoteMode;
-import org.apache.logging.log4j.core.Layout;
-import org.apache.logging.log4j.core.LogEvent;
-import org.apache.logging.log4j.core.config.Configuration;
-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;
-import org.apache.logging.log4j.core.config.plugins.PluginConfiguration;
-import org.apache.logging.log4j.core.config.plugins.PluginFactory;
-import org.apache.logging.log4j.status.StatusLogger;
-
-/**
- * A Comma-Separated Value (CSV) layout to log events.
- *
- * Depends on Apache Commons CSV 1.2.
- *
- * @since 2.4
- */
-@Plugin(name = "CsvLogEventLayout", category = Node.CATEGORY, elementType = Layout.ELEMENT_TYPE, printObject = true)
-public class CsvLogEventLayout extends AbstractCsvLayout {
-
- public static CsvLogEventLayout createDefaultLayout() {
- return new CsvLogEventLayout(null, Charset.forName(DEFAULT_CHARSET), CSVFormat.valueOf(DEFAULT_FORMAT), null, null);
- }
-
- public static CsvLogEventLayout createLayout(final CSVFormat format) {
- return new CsvLogEventLayout(null, Charset.forName(DEFAULT_CHARSET), format, null, null);
- }
-
- @PluginFactory
- public static CsvLogEventLayout createLayout(
- // @formatter:off
- @PluginConfiguration final Configuration config,
- @PluginAttribute(value = "format", defaultString = DEFAULT_FORMAT) final String format,
- @PluginAttribute("delimiter") final Character delimiter,
- @PluginAttribute("escape") final Character escape,
- @PluginAttribute("quote") final Character quote,
- @PluginAttribute("quoteMode") final QuoteMode quoteMode,
- @PluginAttribute("nullString") final String nullString,
- @PluginAttribute("recordSeparator") final String recordSeparator,
- @PluginAttribute(value = "charset", defaultString = DEFAULT_CHARSET) final Charset charset,
- @PluginAttribute("header") final String header,
- @PluginAttribute("footer") final String footer)
- // @formatter:on
- {
-
- final CSVFormat csvFormat = createFormat(format, delimiter, escape, quote, quoteMode, nullString, recordSeparator);
- return new CsvLogEventLayout(config, charset, csvFormat, header, footer);
- }
-
- protected CsvLogEventLayout(final Configuration config, final Charset charset, final CSVFormat csvFormat, final String header, final String footer) {
- super(config, charset, csvFormat, header, footer);
- }
-
- @Override
- public String toSerializable(final LogEvent event) {
- final StringBuilder buffer = getStringBuilder();
- // Revisit when 1.3 is out so that we do not need to create a new
- // printer for each event.
- // No need to close the printer.
- try (final CSVPrinter printer = new CSVPrinter(buffer, getFormat())) {
- printer.print(event.getNanoTime());
- printer.print(event.getTimeMillis());
- printer.print(event.getLevel());
- printer.print(event.getThreadId());
- printer.print(event.getThreadName());
- printer.print(event.getThreadPriority());
- printer.print(event.getMessage().getFormattedMessage());
- printer.print(event.getLoggerFqcn());
- printer.print(event.getLoggerName());
- printer.print(event.getMarker());
- printer.print(event.getThrownProxy());
- printer.print(event.getSource());
- printer.print(event.getContextMap());
- printer.print(event.getContextStack());
- printer.println();
- return buffer.toString();
- } catch (final IOException e) {
- StatusLogger.getLogger().error(event.toString(), e);
- return getFormat().getCommentMarker() + " " + e;
- }
- }
-
-}
+/*
+ * 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.layout;
+
+import java.io.IOException;
+import java.nio.charset.Charset;
+
+import org.apache.commons.csv.CSVFormat;
+import org.apache.commons.csv.CSVPrinter;
+import org.apache.commons.csv.QuoteMode;
+import org.apache.logging.log4j.core.Layout;
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.config.Configuration;
+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;
+import org.apache.logging.log4j.core.config.plugins.PluginConfiguration;
+import org.apache.logging.log4j.core.config.plugins.PluginFactory;
+import org.apache.logging.log4j.status.StatusLogger;
+
+/**
+ * A Comma-Separated Value (CSV) layout to log events.
+ *
+ * Depends on Apache Commons CSV 1.2.
+ *
+ * @since 2.4
+ */
+@Plugin(name = "CsvLogEventLayout", category = Node.CATEGORY, elementType = Layout.ELEMENT_TYPE, printObject = true)
+public class CsvLogEventLayout extends AbstractCsvLayout {
+
+ public static CsvLogEventLayout createDefaultLayout() {
+ return new CsvLogEventLayout(null, Charset.forName(DEFAULT_CHARSET), CSVFormat.valueOf(DEFAULT_FORMAT), null, null);
+ }
+
+ public static CsvLogEventLayout createLayout(final CSVFormat format) {
+ return new CsvLogEventLayout(null, Charset.forName(DEFAULT_CHARSET), format, null, null);
+ }
+
+ @PluginFactory
+ public static CsvLogEventLayout createLayout(
+ // @formatter:off
+ @PluginConfiguration final Configuration config,
+ @PluginAttribute(value = "format", defaultString = DEFAULT_FORMAT) final String format,
+ @PluginAttribute("delimiter") final Character delimiter,
+ @PluginAttribute("escape") final Character escape,
+ @PluginAttribute("quote") final Character quote,
+ @PluginAttribute("quoteMode") final QuoteMode quoteMode,
+ @PluginAttribute("nullString") final String nullString,
+ @PluginAttribute("recordSeparator") final String recordSeparator,
+ @PluginAttribute(value = "charset", defaultString = DEFAULT_CHARSET) final Charset charset,
+ @PluginAttribute("header") final String header,
+ @PluginAttribute("footer") final String footer)
+ // @formatter:on
+ {
+
+ final CSVFormat csvFormat = createFormat(format, delimiter, escape, quote, quoteMode, nullString, recordSeparator);
+ return new CsvLogEventLayout(config, charset, csvFormat, header, footer);
+ }
+
+ protected CsvLogEventLayout(final Configuration config, final Charset charset, final CSVFormat csvFormat, final String header, final String footer) {
+ super(config, charset, csvFormat, header, footer);
+ }
+
+ @Override
+ public String toSerializable(final LogEvent event) {
+ final StringBuilder buffer = getStringBuilder();
+ // Revisit when 1.3 is out so that we do not need to create a new
+ // printer for each event.
+ try (final CSVPrinter printer = new CSVPrinter(buffer, getFormat())) {
+ printer.print(event.getNanoTime());
+ printer.print(event.getTimeMillis());
+ printer.print(event.getLevel());
+ printer.print(event.getThreadId());
+ printer.print(event.getThreadName());
+ printer.print(event.getThreadPriority());
+ printer.print(event.getMessage().getFormattedMessage());
+ printer.print(event.getLoggerFqcn());
+ printer.print(event.getLoggerName());
+ printer.print(event.getMarker());
+ printer.print(event.getThrownProxy());
+ printer.print(event.getSource());
+ printer.print(event.getContextMap());
+ printer.print(event.getContextStack());
+ printer.println();
+ return buffer.toString();
+ } catch (final IOException e) {
+ StatusLogger.getLogger().error(event.toString(), e);
+ return getFormat().getCommentMarker() + " " + e;
+ }
+ }
+
+}
[8/8] logging-log4j2 git commit: Do not use our own deprecated code.
Posted by gg...@apache.org.
Do not use our own deprecated code.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/d3e571f3
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/d3e571f3
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/d3e571f3
Branch: refs/heads/master
Commit: d3e571f37bd9a2ef07e426a1809d3cb1f69c3482
Parents: a15477b
Author: ggregory <gg...@apache.org>
Authored: Sun Apr 17 17:26:34 2016 -0700
Committer: ggregory <gg...@apache.org>
Committed: Sun Apr 17 17:26:34 2016 -0700
----------------------------------------------------------------------
.../logging/log4j/core/AppenderRefLevelJsonTest.java | 12 ++++++------
.../logging/log4j/core/AppenderRefLevelTest.java | 12 ++++++------
.../apache/logging/log4j/core/PatternSelectorTest.java | 12 ++++++------
.../apache/logging/log4j/core/StrictXmlConfigTest.java | 13 +++++++++++--
.../log4j/core/filter/AbstractScriptFilterTest.java | 4 ++--
5 files changed, 31 insertions(+), 22 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/d3e571f3/log4j-core/src/test/java/org/apache/logging/log4j/core/AppenderRefLevelJsonTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/AppenderRefLevelJsonTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/AppenderRefLevelJsonTest.java
index a6c7697..3d9424a 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/AppenderRefLevelJsonTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/AppenderRefLevelJsonTest.java
@@ -52,36 +52,36 @@ public class AppenderRefLevelJsonTest {
@Test
public void logger1() {
- logger1.entry();
+ logger1.traceEntry();
logger1.debug("debug message");
logger1.error("Test Message");
logger1.info("Info Message");
logger1.warn("warn Message");
- logger1.exit();
+ logger1.traceExit();
assertThat(app1.getEvents(), hasSize(6));
assertThat(app2.getEvents(), hasSize(1));
}
@Test
public void logger2() {
- logger2.entry();
+ logger2.traceEntry();
logger2.debug("debug message");
logger2.error("Test Message");
logger2.info("Info Message");
logger2.warn("warn Message");
- logger2.exit();
+ logger2.traceExit();
assertThat(app1.getEvents(), hasSize(2));
assertThat(app2.getEvents(), hasSize(4));
}
@Test
public void logger3() {
- logger3.entry();
+ logger3.traceEntry();
logger3.debug(testMarker, "debug message");
logger3.error("Test Message");
logger3.info(testMarker, "Info Message");
logger3.warn("warn Message");
- logger3.exit();
+ logger3.traceExit();
assertThat(app1.getEvents(), hasSize(4));
}
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/d3e571f3/log4j-core/src/test/java/org/apache/logging/log4j/core/AppenderRefLevelTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/AppenderRefLevelTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/AppenderRefLevelTest.java
index d59c1a0..861ed87 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/AppenderRefLevelTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/AppenderRefLevelTest.java
@@ -53,12 +53,12 @@ public class AppenderRefLevelTest {
@Test
public void logger1() {
- logger1.entry();
+ logger1.traceEntry();
logger1.debug("debug message");
logger1.error("Test Message");
logger1.info("Info Message");
logger1.warn("warn Message");
- logger1.exit();
+ logger1.traceExit();
List<LogEvent> events = app1.getEvents();
assertEquals("Incorrect number of events. Expected 6, actual " + events.size(), 6, events.size());
events = app2.getEvents();
@@ -67,12 +67,12 @@ public class AppenderRefLevelTest {
@Test
public void logger2() {
- logger2.entry();
+ logger2.traceEntry();
logger2.debug("debug message");
logger2.error("Test Message");
logger2.info("Info Message");
logger2.warn("warn Message");
- logger2.exit();
+ logger2.traceExit();
List<LogEvent> events = app1.getEvents();
assertEquals("Incorrect number of events. Expected 2, actual " + events.size(), events.size(), 2);
events = app2.getEvents();
@@ -81,12 +81,12 @@ public class AppenderRefLevelTest {
@Test
public void logger3() {
- logger3.entry();
+ logger3.traceEntry();
logger3.debug(testMarker, "debug message");
logger3.error("Test Message");
logger3.info(testMarker, "Info Message");
logger3.warn("warn Message");
- logger3.exit();
+ logger3.traceExit();
final List<LogEvent> events = app1.getEvents();
assertEquals("Incorrect number of events. Expected 4, actual " + events.size(), 4, events.size());
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/d3e571f3/log4j-core/src/test/java/org/apache/logging/log4j/core/PatternSelectorTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/PatternSelectorTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/PatternSelectorTest.java
index 9fda787..1214e4e 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/PatternSelectorTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/PatternSelectorTest.java
@@ -40,9 +40,9 @@ public class PatternSelectorTest {
@Test
public void testMarkerPatternSelector() throws Exception {
org.apache.logging.log4j.Logger logger = LogManager.getLogger("TestMarkerPatternSelector");
- logger.entry();
+ logger.traceEntry();
logger.info("Hello World");
- logger.exit();
+ logger.traceExit();
final ListAppender app = (ListAppender) context.getRequiredAppender("List");
assertNotNull("No ListAppender", app);
List<String> messages = app.getMessages();
@@ -59,10 +59,10 @@ public class PatternSelectorTest {
public void testScriptPatternSelector() throws Exception {
org.apache.logging.log4j.Logger logger = LogManager.getLogger("TestScriptPatternSelector");
org.apache.logging.log4j.Logger logger2 = LogManager.getLogger("NoLocation");
- logger.entry();
+ logger.traceEntry();
logger.info("Hello World");
logger2.info("No location information");
- logger.exit();
+ logger.traceExit();
final ListAppender app = (ListAppender) context.getRequiredAppender("List2");
assertNotNull("No ListAppender", app);
List<String> messages = app.getMessages();
@@ -82,10 +82,10 @@ public class PatternSelectorTest {
public void testJavaScriptPatternSelector() throws Exception {
org.apache.logging.log4j.Logger logger = LogManager.getLogger("TestJavaScriptPatternSelector");
org.apache.logging.log4j.Logger logger2 = LogManager.getLogger("JavascriptNoLocation");
- logger.entry();
+ logger.traceEntry();
logger.info("Hello World");
logger2.info("No location information");
- logger.exit();
+ logger.traceExit();
final ListAppender app = (ListAppender) context.getRequiredAppender("List3");
assertNotNull("No ListAppender", app);
List<String> messages = app.getMessages();
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/d3e571f3/log4j-core/src/test/java/org/apache/logging/log4j/core/StrictXmlConfigTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/StrictXmlConfigTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/StrictXmlConfigTest.java
index edc428e..f94a60d 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/StrictXmlConfigTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/StrictXmlConfigTest.java
@@ -23,6 +23,7 @@ import java.util.Locale;
import org.apache.logging.log4j.MarkerManager;
import org.apache.logging.log4j.ThreadContext;
import org.apache.logging.log4j.junit.LoggerContextRule;
+import org.apache.logging.log4j.message.EntryMessage;
import org.apache.logging.log4j.message.StructuredDataMessage;
import org.apache.logging.log4j.test.appender.ListAppender;
import org.junit.Before;
@@ -51,8 +52,16 @@ public class StrictXmlConfigTest {
@Test
public void basicFlow() {
- logger.entry();
- logger.exit();
+ final EntryMessage entry = logger.traceEntry();
+ logger.traceExit(entry);
+ final List<LogEvent> events = app.getEvents();
+ assertEquals("Incorrect number of events. Expected 2, actual " + events.size(), 2, events.size());
+ }
+
+ @Test
+ public void basicFlowDeprecated() {
+ logger.traceEntry();
+ logger.traceExit();
final List<LogEvent> events = app.getEvents();
assertEquals("Incorrect number of events. Expected 2, actual " + events.size(), 2, events.size());
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/d3e571f3/log4j-core/src/test/java/org/apache/logging/log4j/core/filter/AbstractScriptFilterTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/filter/AbstractScriptFilterTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/filter/AbstractScriptFilterTest.java
index 56fa8f4..a2e949c 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/filter/AbstractScriptFilterTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/filter/AbstractScriptFilterTest.java
@@ -38,7 +38,7 @@ public abstract class AbstractScriptFilterTest {
@Test
public void testGroovyFilter() throws Exception {
Logger logger = LogManager.getLogger("TestGroovyFilter");
- logger.entry();
+ logger.traceEntry();
logger.info("This should not be logged");
ThreadContext.put("UserId", "JohnDoe");
logger.info("This should be logged");
@@ -56,7 +56,7 @@ public abstract class AbstractScriptFilterTest {
@Test
public void testJavascriptFilter() throws Exception {
Logger logger = LogManager.getLogger("TestJavaScriptFilter");
- logger.entry();
+ logger.traceEntry();
logger.info("This should not be logged");
ThreadContext.put("UserId", "JohnDoe");
logger.info("This should be logged");
[4/8] logging-log4j2 git commit: Fix per Matt's comments on the ML.
Posted by gg...@apache.org.
Fix per Matt's comments on the ML.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/a990c752
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/a990c752
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/a990c752
Branch: refs/heads/master
Commit: a990c75251bdc28123b48ceb67e54f7face71af7
Parents: 7380b27
Author: ggregory <gg...@apache.org>
Authored: Sun Apr 17 17:03:45 2016 -0700
Committer: ggregory <gg...@apache.org>
Committed: Sun Apr 17 17:03:45 2016 -0700
----------------------------------------------------------------------
.../log4j/core/net/server/TcpSocketServer.java | 19 ++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/a990c752/log4j-core/src/main/java/org/apache/logging/log4j/core/net/server/TcpSocketServer.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/server/TcpSocketServer.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/server/TcpSocketServer.java
index 9103a01..f32fbe8 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/server/TcpSocketServer.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/server/TcpSocketServer.java
@@ -32,6 +32,7 @@ import java.util.concurrent.ConcurrentMap;
import org.apache.logging.log4j.core.config.ConfigurationFactory;
import org.apache.logging.log4j.core.util.Log4jThread;
+import org.apache.logging.log4j.message.EntryMessage;
/**
* Listens for events over a socket connection.
@@ -56,7 +57,7 @@ public class TcpSocketServer<T extends InputStream> extends AbstractSocketServer
@Override
public void run() {
- logger.traceEntry();
+ final EntryMessage entry = logger.traceEntry();
boolean closed = false;
try {
try {
@@ -80,7 +81,7 @@ public class TcpSocketServer<T extends InputStream> extends AbstractSocketServer
} finally {
handlers.remove(Long.valueOf(getId()));
}
- logger.traceExit();
+ logger.traceExit(entry);
}
public void shutdown() {
@@ -218,7 +219,7 @@ public class TcpSocketServer<T extends InputStream> extends AbstractSocketServer
*/
@Override
public void run() {
- logger.traceEntry();
+ final EntryMessage entry = logger.traceEntry();
while (isActive()) {
if (serverSocket.isClosed()) {
return;
@@ -240,14 +241,14 @@ public class TcpSocketServer<T extends InputStream> extends AbstractSocketServer
} catch (final IOException e) {
if (serverSocket.isClosed()) {
// OK we're done.
- logger.traceExit();
+ logger.traceExit(entry);
return;
}
logger.error("Exception encountered on accept. Ignoring. Stack Trace :", e);
}
}
- for (final Map.Entry<Long, SocketHandler> entry : handlers.entrySet()) {
- final SocketHandler handler = entry.getValue();
+ for (final Map.Entry<Long, SocketHandler> handlerEntry : handlers.entrySet()) {
+ final SocketHandler handler = handlerEntry.getValue();
handler.shutdown();
try {
handler.join();
@@ -255,7 +256,7 @@ public class TcpSocketServer<T extends InputStream> extends AbstractSocketServer
// Ignore the exception
}
}
- logger.traceExit();
+ logger.traceExit(entry);
}
/**
@@ -264,10 +265,10 @@ public class TcpSocketServer<T extends InputStream> extends AbstractSocketServer
* @throws IOException if the server socket could not be closed
*/
public void shutdown() throws IOException {
- logger.traceEntry();
+ final EntryMessage entry = logger.traceEntry();
setActive(false);
Thread.currentThread().interrupt();
serverSocket.close();
- logger.traceExit();
+ logger.traceExit(entry);
}
}
[7/8] logging-log4j2 git commit: Remove dead comment.
Posted by gg...@apache.org.
Remove dead comment.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/a15477ba
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/a15477ba
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/a15477ba
Branch: refs/heads/master
Commit: a15477ba51bac258238a23cc3fd837cb1a57d1a2
Parents: ce36b37
Author: ggregory <gg...@apache.org>
Authored: Sun Apr 17 17:13:36 2016 -0700
Committer: ggregory <gg...@apache.org>
Committed: Sun Apr 17 17:13:36 2016 -0700
----------------------------------------------------------------------
.../log4j/core/layout/CsvParameterLayout.java | 207 +++++++++----------
1 file changed, 103 insertions(+), 104 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/a15477ba/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/CsvParameterLayout.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/CsvParameterLayout.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/CsvParameterLayout.java
index 9c792e7..dcae328 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/CsvParameterLayout.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/CsvParameterLayout.java
@@ -1,104 +1,103 @@
-/*
- * 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.layout;
-
-import java.io.IOException;
-import java.nio.charset.Charset;
-
-import org.apache.commons.csv.CSVFormat;
-import org.apache.commons.csv.CSVPrinter;
-import org.apache.commons.csv.QuoteMode;
-import org.apache.logging.log4j.core.Layout;
-import org.apache.logging.log4j.core.LogEvent;
-import org.apache.logging.log4j.core.config.Configuration;
-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;
-import org.apache.logging.log4j.core.config.plugins.PluginConfiguration;
-import org.apache.logging.log4j.core.config.plugins.PluginFactory;
-import org.apache.logging.log4j.message.Message;
-import org.apache.logging.log4j.status.StatusLogger;
-
-/**
- * A Comma-Separated Value (CSV) layout to log event parameters.
- * The event message is currently ignored.
- *
- * <p>
- * Best used with:
- * </p>
- * <p>
- * {@code logger.debug(new ObjectArrayMessage(1, 2, "Bob"));}
- * </p>
- *
- * Depends on Apache Commons CSV 1.2.
- *
- * @since 2.4
- */
-@Plugin(name = "CsvParameterLayout", category = Node.CATEGORY, elementType = Layout.ELEMENT_TYPE, printObject = true)
-public class CsvParameterLayout extends AbstractCsvLayout {
-
- public static AbstractCsvLayout createDefaultLayout() {
- return new CsvParameterLayout(null, Charset.forName(DEFAULT_CHARSET), CSVFormat.valueOf(DEFAULT_FORMAT), null, null);
- }
-
- public static AbstractCsvLayout createLayout(final CSVFormat format) {
- return new CsvParameterLayout(null, Charset.forName(DEFAULT_CHARSET), format, null, null);
- }
-
- @PluginFactory
- public static AbstractCsvLayout createLayout(
- // @formatter:off
- @PluginConfiguration final Configuration config,
- @PluginAttribute(value = "format", defaultString = DEFAULT_FORMAT) final String format,
- @PluginAttribute("delimiter") final Character delimiter,
- @PluginAttribute("escape") final Character escape,
- @PluginAttribute("quote") final Character quote,
- @PluginAttribute("quoteMode") final QuoteMode quoteMode,
- @PluginAttribute("nullString") final String nullString,
- @PluginAttribute("recordSeparator") final String recordSeparator,
- @PluginAttribute(value = "charset", defaultString = DEFAULT_CHARSET) final Charset charset,
- @PluginAttribute("header") final String header,
- @PluginAttribute("footer") final String footer)
- // @formatter:on
- {
-
- final CSVFormat csvFormat = createFormat(format, delimiter, escape, quote, quoteMode, nullString, recordSeparator);
- return new CsvParameterLayout(config, charset, csvFormat, header, footer);
- }
-
- public CsvParameterLayout(final Configuration config, final Charset charset, final CSVFormat csvFormat, final String header, final String footer) {
- super(config, charset, csvFormat, header, footer);
- }
-
- @Override
- public String toSerializable(final LogEvent event) {
- final Message message = event.getMessage();
- final Object[] parameters = message.getParameters();
- final StringBuilder buffer = getStringBuilder();
- // Revisit when 1.3 is out so that we do not need to create a new
- // printer for each event.
- // No need to close the printer.
- try (final CSVPrinter printer = new CSVPrinter(buffer, getFormat())) {
- printer.printRecord(parameters);
- return buffer.toString();
- } catch (final IOException e) {
- StatusLogger.getLogger().error(message, e);
- return getFormat().getCommentMarker() + " " + e;
- }
- }
-
-}
+/*
+ * 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.layout;
+
+import java.io.IOException;
+import java.nio.charset.Charset;
+
+import org.apache.commons.csv.CSVFormat;
+import org.apache.commons.csv.CSVPrinter;
+import org.apache.commons.csv.QuoteMode;
+import org.apache.logging.log4j.core.Layout;
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.config.Configuration;
+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;
+import org.apache.logging.log4j.core.config.plugins.PluginConfiguration;
+import org.apache.logging.log4j.core.config.plugins.PluginFactory;
+import org.apache.logging.log4j.message.Message;
+import org.apache.logging.log4j.status.StatusLogger;
+
+/**
+ * A Comma-Separated Value (CSV) layout to log event parameters.
+ * The event message is currently ignored.
+ *
+ * <p>
+ * Best used with:
+ * </p>
+ * <p>
+ * {@code logger.debug(new ObjectArrayMessage(1, 2, "Bob"));}
+ * </p>
+ *
+ * Depends on Apache Commons CSV 1.2.
+ *
+ * @since 2.4
+ */
+@Plugin(name = "CsvParameterLayout", category = Node.CATEGORY, elementType = Layout.ELEMENT_TYPE, printObject = true)
+public class CsvParameterLayout extends AbstractCsvLayout {
+
+ public static AbstractCsvLayout createDefaultLayout() {
+ return new CsvParameterLayout(null, Charset.forName(DEFAULT_CHARSET), CSVFormat.valueOf(DEFAULT_FORMAT), null, null);
+ }
+
+ public static AbstractCsvLayout createLayout(final CSVFormat format) {
+ return new CsvParameterLayout(null, Charset.forName(DEFAULT_CHARSET), format, null, null);
+ }
+
+ @PluginFactory
+ public static AbstractCsvLayout createLayout(
+ // @formatter:off
+ @PluginConfiguration final Configuration config,
+ @PluginAttribute(value = "format", defaultString = DEFAULT_FORMAT) final String format,
+ @PluginAttribute("delimiter") final Character delimiter,
+ @PluginAttribute("escape") final Character escape,
+ @PluginAttribute("quote") final Character quote,
+ @PluginAttribute("quoteMode") final QuoteMode quoteMode,
+ @PluginAttribute("nullString") final String nullString,
+ @PluginAttribute("recordSeparator") final String recordSeparator,
+ @PluginAttribute(value = "charset", defaultString = DEFAULT_CHARSET) final Charset charset,
+ @PluginAttribute("header") final String header,
+ @PluginAttribute("footer") final String footer)
+ // @formatter:on
+ {
+
+ final CSVFormat csvFormat = createFormat(format, delimiter, escape, quote, quoteMode, nullString, recordSeparator);
+ return new CsvParameterLayout(config, charset, csvFormat, header, footer);
+ }
+
+ public CsvParameterLayout(final Configuration config, final Charset charset, final CSVFormat csvFormat, final String header, final String footer) {
+ super(config, charset, csvFormat, header, footer);
+ }
+
+ @Override
+ public String toSerializable(final LogEvent event) {
+ final Message message = event.getMessage();
+ final Object[] parameters = message.getParameters();
+ final StringBuilder buffer = getStringBuilder();
+ // Revisit when 1.3 is out so that we do not need to create a new
+ // printer for each event.
+ try (final CSVPrinter printer = new CSVPrinter(buffer, getFormat())) {
+ printer.printRecord(parameters);
+ return buffer.toString();
+ } catch (final IOException e) {
+ StatusLogger.getLogger().error(message, e);
+ return getFormat().getCommentMarker() + " " + e;
+ }
+ }
+
+}
[2/8] logging-log4j2 git commit: Remove unused imports.
Posted by gg...@apache.org.
Remove unused imports.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/b61fbbd4
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/b61fbbd4
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/b61fbbd4
Branch: refs/heads/master
Commit: b61fbbd4c4516fea90fedeb22777ac13cd089b1b
Parents: a7f60a2
Author: ggregory <gg...@apache.org>
Authored: Sun Apr 17 16:56:39 2016 -0700
Committer: ggregory <gg...@apache.org>
Committed: Sun Apr 17 16:56:39 2016 -0700
----------------------------------------------------------------------
.../apache/logging/log4j/core/appender/MemoryMappedFileManager.java | 1 -
.../apache/logging/log4j/core/appender/RandomAccessFileManager.java | 1 -
.../log4j/core/appender/rolling/RollingRandomAccessFileManager.java | 1 -
3 files changed, 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/b61fbbd4/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/MemoryMappedFileManager.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/MemoryMappedFileManager.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/MemoryMappedFileManager.java
index 1986993..cfb5a08 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/MemoryMappedFileManager.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/MemoryMappedFileManager.java
@@ -34,7 +34,6 @@ import java.util.Map;
import java.util.Objects;
import org.apache.logging.log4j.core.Layout;
-import org.apache.logging.log4j.core.layout.ByteBufferDestination;
import org.apache.logging.log4j.core.util.Closer;
import org.apache.logging.log4j.core.util.NullOutputStream;
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/b61fbbd4/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RandomAccessFileManager.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RandomAccessFileManager.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RandomAccessFileManager.java
index 674c25f..265aef0 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RandomAccessFileManager.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RandomAccessFileManager.java
@@ -26,7 +26,6 @@ import java.util.HashMap;
import java.util.Map;
import org.apache.logging.log4j.core.Layout;
-import org.apache.logging.log4j.core.layout.ByteBufferDestination;
import org.apache.logging.log4j.core.util.NullOutputStream;
/**
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/b61fbbd4/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManager.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManager.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManager.java
index e76dba6..7a3e43d 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManager.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManager.java
@@ -26,7 +26,6 @@ import java.nio.ByteBuffer;
import org.apache.logging.log4j.core.Layout;
import org.apache.logging.log4j.core.appender.AppenderLoggingException;
import org.apache.logging.log4j.core.appender.ManagerFactory;
-import org.apache.logging.log4j.core.layout.ByteBufferDestination;
import org.apache.logging.log4j.core.util.NullOutputStream;
/**
[5/8] logging-log4j2 git commit: Do not use our own deprecated code.
Posted by gg...@apache.org.
Do not use our own deprecated code.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/6b9955df
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/6b9955df
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/6b9955df
Branch: refs/heads/master
Commit: 6b9955df6b67ae4eb7cda187dac50a88760d7eef
Parents: a990c75
Author: ggregory <gg...@apache.org>
Authored: Sun Apr 17 17:04:47 2016 -0700
Committer: ggregory <gg...@apache.org>
Committed: Sun Apr 17 17:04:47 2016 -0700
----------------------------------------------------------------------
.../java/org/apache/logging/log4j/core/LoggerUpdateTest.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/6b9955df/log4j-core/src/test/java/org/apache/logging/log4j/core/LoggerUpdateTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/LoggerUpdateTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/LoggerUpdateTest.java
index eb698ab..574236c 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/LoggerUpdateTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/LoggerUpdateTest.java
@@ -50,7 +50,7 @@ public class LoggerUpdateTest {
@Test
public void resetLevel() {
final org.apache.logging.log4j.Logger logger = context.getLogger("com.apache.test");
- logger.entry();
+ logger.traceEntry();
List<LogEvent> events = app.getEvents();
assertEquals("Incorrect number of events. Expected 1, actual " + events.size(), 1, events.size());
app.clear();
@@ -62,7 +62,7 @@ public class LoggerUpdateTest {
*/
loggerConfig.setLevel(Level.DEBUG);
ctx.updateLoggers(); // This causes all Loggers to refetch information from their LoggerConfig.
- logger.entry();
+ logger.traceEntry();
events = app.getEvents();
assertEquals("Incorrect number of events. Expected 0, actual " + events.size(), 0, events.size());
}
[3/8] logging-log4j2 git commit: Add traceEntry/Exit() tests.
Posted by gg...@apache.org.
Add traceEntry/Exit() tests.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/7380b27e
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/7380b27e
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/7380b27e
Branch: refs/heads/master
Commit: 7380b27e15465d943cdeecb6ec35430859406256
Parents: b61fbbd
Author: ggregory <gg...@apache.org>
Authored: Sun Apr 17 16:59:03 2016 -0700
Committer: ggregory <gg...@apache.org>
Committed: Sun Apr 17 16:59:03 2016 -0700
----------------------------------------------------------------------
.../java/org/apache/logging/log4j/core/LoggerTest.java | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7380b27e/log4j-core/src/test/java/org/apache/logging/log4j/core/LoggerTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/LoggerTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/LoggerTest.java
index 7ba6a89..7a2e01e 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/LoggerTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/LoggerTest.java
@@ -89,8 +89,8 @@ public class LoggerTest {
@Test
public void basicFlow() {
- logger.entry();
- logger.exit();
+ logger.traceEntry();
+ logger.traceExit();
final List<LogEvent> events = app.getEvents();
assertEventCount(events, 2);
}
@@ -98,6 +98,14 @@ public class LoggerTest {
@Test
public void simpleFlow() {
logger.entry(CONFIG);
+ logger.traceExit(0);
+ final List<LogEvent> events = app.getEvents();
+ assertEventCount(events, 2);
+ }
+
+ @Test
+ public void simpleFlowDepreacted() {
+ logger.entry(CONFIG);
logger.exit(0);
final List<LogEvent> events = app.getEvents();
assertEventCount(events, 2);