[
https://issues.apache.org/jira/browse/KARAF-5877?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16589063#comment-16589063
]
ASF GitHub Bot commented on KARAF-5877:
---------------------------------------
bakejeyner closed pull request #599: KARAF-5877 log4j2 appending error when
using log4j2 XML configuration
URL: https://github.com/apache/karaf/pull/599
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git
a/log/src/main/java/org/apache/karaf/log/core/internal/LogServiceLog4j2XmlImpl.java
b/log/src/main/java/org/apache/karaf/log/core/internal/LogServiceLog4j2XmlImpl.java
index 843bf51502..d50eea4108 100644
---
a/log/src/main/java/org/apache/karaf/log/core/internal/LogServiceLog4j2XmlImpl.java
+++
b/log/src/main/java/org/apache/karaf/log/core/internal/LogServiceLog4j2XmlImpl.java
@@ -136,8 +136,7 @@ else if (!Level.isDefault(level)) {
* indenting it as needed.
*/
static void insertIndented(Element loggers, Element element, boolean
atBeginning) {
- NodeList loggerElements = loggers.getElementsByTagName("*");
- if (atBeginning && loggerElements.getLength() > 0) {
+ if (atBeginning && loggers.hasChildNodes()) {
Node insertBefore = loggers.getFirstChild();
if (insertBefore != null) {
if (insertBefore.getNodeType() == Node.TEXT_NODE) {
@@ -150,7 +149,7 @@ static void insertIndented(Element loggers, Element
element, boolean atBeginning
loggers.appendChild(element);
}
} else {
- Node insertAfter = loggerElements.getLength() > 0 ?
loggerElements.item(loggerElements.getLength() - 1) : null;
+ Node insertAfter = loggers.getLastChild().getPreviousSibling();
if (insertAfter != null) {
if (insertAfter.getPreviousSibling() != null &&
insertAfter.getPreviousSibling().getNodeType() == Node.TEXT_NODE) {
String indent =
insertAfter.getPreviousSibling().getTextContent();
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> log4j2 appending error when using log4j2 XML configuration
> ----------------------------------------------------------
>
> Key: KARAF-5877
> URL: https://issues.apache.org/jira/browse/KARAF-5877
> Project: Karaf
> Issue Type: Bug
> Components: karaf-logging
> Affects Versions: 4.2.0
> Reporter: Jacob Beyner
> Priority: Trivial
> Fix For: 4.2.0
>
>
> {{LogServiceLog4j2XmlImpl}} will throw an {{org.w3c.dom.DOMException:
> NOT_FOUND_ERR}} when the corresponding log4j2 configuration file has an
> element with children as the last element in the {{<Loggers>}} element. This
> causes the {{log:tail}} command to display the logs and error out immediately.
> The reason for this is the {{LogServiceLog4j2XmlImpl.insertIndented}} method.
> It will eventually execute [this
> line|https://github.com/apache/karaf/blob/master/log/src/main/java/org/apache/karaf/log/core/internal/LogServiceLog4j2XmlImpl.java#L159],
> responsible for throwing the error.
> This is because the {{loggers}} object is a flat collection of the
> {{Loggers}} element's children, and the {{insertAfter}} Node *can* be a
> nested child instead of a first level child. Then, when
> {{loggers.insertBefore(node, insertAfter.getNextSibling())}} is called, and
> {{insertAfter}} is not a first level child of the {{Loggers}} element, the
> exception is thrown. [This is becuase the {{Node.insertBefore}} method
> requires the second argument to be a direct child of the node calling the
> method|https://docs.oracle.com/javase/7/docs/api/org/w3c/dom/Node.html#insertBefore(org.w3c.dom.Node,%20org.w3c.dom.Node)].
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)