-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expanded more elements to Log4j-config.xsd #1441
Conversation
While certainly not a complete addition of all missing appenders, or all of the possible configuration of those appenders, I added some of the more common ones, including: ScriptAppenderSelector, RollingFile, File, and Null. I also added the charset attribute to PatternLayout and the level attribute to AppenderRef.
thanks for the PR. This is a very old outstanding bug (cf. LOG4J2-170). Actually the |
A couple of months ago we published an automatically generated XML Schema for all Log4j 2 and 3 module. You can find it at: https://logging.apache.org/xml/ns/ The schema is generated using a new internal tool ( |
Thank you. I ran into a some problems using the new one at https://logging.apache.org/xml/ns/. <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configuration>
<Configuration xmlns="https://logging.apache.org/xml/ns"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://logging.apache.org/xml/ns https://logging.apache.org/xml/ns/log4j-config-2.xsd"
status="WARN">
<Properties>
<Property name="root.logging.level">${sys:myapp.root.logging.level:-${sys:rootLogger.level:-WARN}}</Property>
</Properties>
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%date{ABSOLUTE} %class %method - %message%n%throwable" />
</Console>
</Appenders>
<Loggers>
<Root level="${root.logging.level}">
<AppenderRef ref="Console" />
</Root>
</Loggers>
</Configuration> The new XSD incorrectly points out two problems:
Note that the use case for the way I've written the above configuration is that if I start my Java Virtual Machine with |
This is a limitation of the current
The generated schema doesn't play well with arbiters or property substitution expressions:
We could add an option to |
I would not be in favor of this change. This will practically remove the IDE guidance provided using the XSD, which IMHO, is the point of publishing an XSD in our case. OTOH, I see the point that @krallus, are you trying to (manually) validate your |
Yes, my IDE flags the XML as having errors if I use the XSD at https://logging.apache.org/xml/ns/log4j-config-2.xsd when I have any property substitution. I think property substitution in Log4j XML configurations is probably quite common. I do it in many places. I just provided a simple example. Personally, I would be in favour of making all attributes be of type However, there is a way to define an XSD that will grant both IDE guidance for attribute values and allow for any string at the expense of slightly more sophistication in the XSD. Here is an oversimplified example just to demonstrate how this can be done. Example XSD file that allows a list for IDE guidance but will also validate any string. Note the "levelOrSubstitution" type: <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:simpleType name="levelOrSubstitution">
<xs:union>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="TRACE" />
<xs:enumeration value="DEBUG" />
<xs:enumeration value="INFO" />
<xs:enumeration value="WARN" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value=".+" />
</xs:restriction>
</xs:simpleType>
</xs:union>
</xs:simpleType>
<!-- Root element definition -->
<xs:element name="Configuration">
<xs:complexType>
<xs:sequence>
<xs:element name="Root">
<xs:complexType>
<xs:sequence>
<xs:element name="AppenderRef">
<xs:complexType>
<xs:attribute name="ref" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="level" type="levelOrSubstitution" use="required" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema> Valid XML File: <?xml version="1.0" encoding="UTF-8"?>
<Configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="testconfig.xsd">
<Root level="${sys:myapp.root.logging.level:-${sys:rootLogger.level:-WARN}}">
<AppenderRef ref="FileRfc5424Inspired" />
</Root>
</Configuration> Eclipse IDE guidance when filling out the XML: Note that for the I hope that helps some. |
@ppkarwasz , I will report the |
Thanks, I have opened apache/logging-log4j-tools#135 and apache/logging-log4j-tools#134 to implement your suggestions. |
@krallus, loved the |
While certainly not a complete addition of all missing appenders, or all of the possible configuration of those appenders, I added some of the more common ones that I use, including: ScriptAppenderSelector, RollingFile, File, and Null. I also added the charset attribute to PatternLayout and the level attribute to AppenderRef.
Please ignore whitespace when comparing. The previous version had some elements that did not line up and so I simply reformatted the whole thing.
Note that I edited the file in place and did not run any tests. I'm making the assumption that this file is here for convenience and no tests actually rely on it.