AW: Log4j2 Appender attributes with strict xml config
Hi, just checking if my previous mail went to spamfolder or something because I got no feedback yet. Best Regards, Alex -Ursprüngliche Nachricht- Von: Rathai, Alexander Gesendet: Donnerstag, 17. Oktober 2013 18:16 An: log4j-user@logging.apache.org Betreff: AW: Log4j2 Appender attributes with strict xml config *snip* - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
AW: Log4j2 Appender attributes with strict xml config
Hi, will do as soon as I got some spare time. I already checked out the trunk. I have to admit that my solution is a bit dirty (imho) and there's a warning when validating a config that uses KeyValuePairs on Appenders. When I make a diff I'll patch the original classes and thus make sure that everything is set up nicely. Best Regards, Alex -Ursprüngliche Nachricht- Von: Remko Popma [mailto:remko.po...@gmail.com] Gesendet: Mittwoch, 16. Oktober 2013 16:40 An: Log4J Users List Betreff: Re: Log4j2 Appender attributes with strict xml config On Wednesday, October 16, 2013, Gary Gregory wrote: On Wed, Oct 16, 2013 at 8:48 AM, Remko Popma remko.po...@gmail.comjavascript:; wrote: Perfection may be hard to achieve, but if Alexander's suggestions are an improvement over the current schema, should we add them to the current code base? Probably but where are they? It looks like some text was lost in a reply to this thread. Gary Hm, it's a bit hard to do this via mail (but perhaps that's just me...) Alexander, would you mind raising a JIRA ticket and appending your modifications to it? A diff patch file would be ideal. Best regards, Remko Remko On Tuesday, October 15, 2013, Gary Gregory wrote: On Mon, Oct 14, 2013 at 11:10 AM, Ralph Goers ralph.go...@dslextreme.com javascript:; javascript:; wrote: On Oct 14, 2013, at 7:31 AM, Gary Gregory garydgreg...@gmail.comjavascript:; javascript:; wrote: The current idea I have is that the XML Schema would reflect exactly the code that is running. We should start with that. AFAIK, the current code we have does not allow open-ended XML fragments, but I could be wrong... Gary Of course it allows open-ended XML fragments. If the user provides their own Appender as a plugin they are free to create other plugins that the Appender can then reference. The same is true for Filters, Lookups, etc. XMLConfiguration and JSONConfiguration don't care about specific element names - only that they map to a defined plugin. So any scheme you come up with to generate a fully strict schema would have to be able to account for user defined plugins. I should have been more specific, or there is another piece I do not understand. If I or Alexander provide our own Appender, they will be annotated with Log4j2 annotations. Today, yes, the XML is open-ended, but not per XML Schema. In my imaginary yet-to-be-implemented system, you would tell Log4j, at developement or build time of your app, to rebuild the metadata such that: (1) the normal config knows about my custom appender, and (2) I can generate a new XML Schema. Gary Ralph - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.orgjavascript:; javascript:; For additional commands, e-mail: log4j-user-h...@logging.apache.orgjavascript:; javascript:; -- E-Mail: garydgreg...@gmail.com javascript:; javascript:; | ggreg...@apache.org javascript:; javascript:; Java Persistence with Hibernate, Second Edition JUnit in Action, Second Edition Spring Batch in Action Blog: http://garygregory.wordpress.com Home: http://garygregory.com/ Tweet! http://twitter.com/GaryGregory -- --- To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.orgjavascript:; javascript:; For additional commands, e-mail: log4j-user-h...@logging.apache.orgjavascript:; javascript:; -- E-Mail: garydgreg...@gmail.com javascript:; | ggreg...@apache.orgjavascript:; Java Persistence with Hibernate, Second Edition http://www.manning.com/bauer3/ JUnit in Action, Second Edition http://www.manning.com/tahchiev/ Spring Batch in Action http://www.manning.com/templier/ Blog: http://garygregory.wordpress.com Home: http://garygregory.com/ Tweet! http://twitter.com/GaryGregory - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
AW: Log4j2 Appender attributes with strict xml config
/ -xs:attribute name=advertiser type=xs:string/ +xs:attribute name=verbose type=xs:boolean/ /xs:complexType xs:complexType name=PropertiesType xs:sequence -xs:element name=Property type=PropertyType/ +xs:element name=Property type=PropertyType minOccurs=1 maxOccurs=unbounded/ /xs:sequence /xs:complexType xs:complexType name=AppenderType xs:sequence + xs:element name=Parameter type=ParameterType minOccurs=0 maxOccurs=unbounded/ xs:element name=Layout type=LayoutType minOccurs=0/ xs:choice minOccurs=0 maxOccurs=1 xs:element name=Filters type=FiltersType/ @@ -65,6 +71,13 @@ /xs:extension /xs:simpleContent /xs:complexType +xs:complexType name=ParameterType +xs:simpleContent +xs:extension base=xs:string +xs:attribute name=name type=xs:string/ +/xs:extension +/xs:simpleContent +/xs:complexType xs:complexType name=KeyValuePairType xs:simpleContent xs:extension base=xs:string The config can then be strict, the general structure of the document validated but one is still able to use custom Plugins. Not the ideal world scenario Gary wanted (which I'd appreciate) but still an improvement imho. Best Regards, Alex -Ursprüngliche Nachricht- Von: Rathai, Alexander Gesendet: Donnerstag, 17. Oktober 2013 09:15 An: log4j-user@logging.apache.org Betreff: AW: Log4j2 Appender attributes with strict xml config Hi, will do as soon as I got some spare time. I already checked out the trunk. I have to admit that my solution is a bit dirty (imho) and there's a warning when validating a config that uses KeyValuePairs on Appenders. When I make a diff I'll patch the original classes and thus make sure that everything is set up nicely. Best Regards, Alex -Ursprüngliche Nachricht- Von: Remko Popma [mailto:remko.po...@gmail.com] Gesendet: Mittwoch, 16. Oktober 2013 16:40 An: Log4J Users List Betreff: Re: Log4j2 Appender attributes with strict xml config On Wednesday, October 16, 2013, Gary Gregory wrote: On Wed, Oct 16, 2013 at 8:48 AM, Remko Popma remko.po...@gmail.comjavascript:; wrote: Perfection may be hard to achieve, but if Alexander's suggestions are an improvement over the current schema, should we add them to the current code base? Probably but where are they? It looks like some text was lost in a reply to this thread. Gary Hm, it's a bit hard to do this via mail (but perhaps that's just me...) Alexander, would you mind raising a JIRA ticket and appending your modifications to it? A diff patch file would be ideal. Best regards, Remko *snip old conversation* - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
AW: Log4j2 Appender attributes with strict xml config
So basically when you want strict validation you want it really strict, i.e. not only for the base types like appenders, filters but also their attributes? As far as I understand that would result in a bigger schema where each type is defined in the schema and the config looks more like the non-strict version. User supplied types would be impossible then, unless they are defined as a generic type in the schema which allows for KeyValuePairs or such (like I did in the edited schema below). Best Regards, Alex -Ursprüngliche Nachricht- Von: Gary Gregory [mailto:garydgreg...@gmail.com] Gesendet: Montag, 14. Oktober 2013 16:18 An: Log4J Users List Betreff: Re: Log4j2 Appender attributes with strict xml config Alexander , XML validation against the XML Schema is not fully baked because the Log4j 2 XML Schema is incomplete. Due to the current dynamic nature of the configuration file (it's schema is tied to the Java code and the annotations used), we need to generate the XML Schema based on these annotations in the same way that the annotations are currently processed to create the metadata configuration. Simone had proposed a different to do configuration, but that has not gone anywhere yet, and I am not sure it dealt with XML validation. Gary On Mon, Oct 14, 2013 at 10:09 AM, alexander.rat...@materna.de wrote: Hi, I'm using log4j2-beta9 and want to configure it using a log4j2.xml in strict mode. My issue is: how do I specify attributes that are not in the shipped schema file? An Example: ?xml version=1.0 encoding=UTF-8 ? Configuration status=DEBUG strict=true monitorInterval=5 name=TestingAttributes verbose=true xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance; xsi:noNamespaceSchemaLocation=Log4j-config.xsd Properties /Properties Appenders Appender type=Console name=SYSERR target=SYSTEM_ERR !-- cvc-complex-type.3.2.2: Attribute 'target' is not allowed to appear in element 'Appender'. -- Layout Type=PatternLayout Pattern%date{dd.MM. HH:mm:ss,SSS} %5p %logger %m%n/Pattern /Layout Filters Filter type=MarkerFilter marker=FLOW onMatch=DENY onMismatch=NEUTRAL / Filter type=MarkerFilter marker=EXCEPTION onMatch=DENY onMismatch=NEUTRAL / /Filters /Appender /Appenders Loggers Root level=debug AppenderRef ref=SYSERR / /Root /Loggers /Configuration Notice that I want to set the appender to have the target SYSTEM_ERR but the attribute is not allowed in strict mode. target=SYSTEM_ERR !-- cvc-complex-type.3.2.2: Attribute 'target' is not allowed to appear in element 'Appender'. -- I could always edit the Log4j-config.xsd and allow that attribute there but that would be kind of wrong also because not all appenders have a target attribute. As searching the web didn't help me so far, I'm asking you: Is there anything I'm missing in configuring Log4j2 in strict XML mode? I am for now using the following classes as a workaround: import org.apache.logging.log4j.core.config.*; import org.apache.logging.log4j.core.config.plugins.*; /** * Simple ConfigurationFactory that returns a {@link StrictXMLConfigurationFactory} * * @author a href=mailto:alexander.rat...@materna.de;Alexander Rathai/a */ @Plugin(name = StrictXMLConfigurationFactory, category = ConfigurationFactory) @Order(4) public class StrictXMLConfigurationFactory extends ConfigurationFactory { /** * Valid file extensions for XML files. */ public static final String[] SUFFIXES = new String[]{.xml}; /** * @see org.apache.logging.log4j.core.config.ConfigurationFactory#getConfigura tion(org.apache.logging.log4j.core.config.ConfigurationFactory.Configu rationSource) */ @Override public Configuration getConfiguration(ConfigurationSource source) { return new StrictXMLConfiguration(source); } /** * @see org.apache.logging.log4j.core.config.ConfigurationFactory#getSupported Types() */ @Override public String[] getSupportedTypes() { return XMLConfigurationFactory.SUFFIXES; } } And import java.util.*; import org.apache.logging.log4j.core.config.*; import org.apache.logging.log4j.core.config.ConfigurationFactory.Configuratio nSource; /** * Lets the base class {@link XMLConfiguration} do all