Log4j2 Appender attributes with strict xml config

2013-10-14 Thread Alexander.Rathai
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#getConfiguration(org.apache.logging.log4j.core.config.ConfigurationFactory.ConfigurationSource)

 */

@Override

public Configuration getConfiguration(ConfigurationSource source) {

return new StrictXMLConfiguration(source);

}





/**

 * @see 
org.apache.logging.log4j.core.config.ConfigurationFactory#getSupportedTypes()

 */

@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.ConfigurationSource;





/**

 * Lets the base class {@link XMLConfiguration} do all the hard work and 
patch the object tree before it is being used by {@link BaseConfiguration}

 *

 * @author a href=mailto:alexander.rat...@materna.de;Alexander Rathai/a

 */

public class StrictXMLConfiguration extends XMLConfiguration {



/**

 * @param configSource

 */

public StrictXMLConfiguration(ConfigurationSource configSource) {

super(configSource);

}





/**

 * @see 
org.apache.logging.log4j.core.config.XMLConfiguration#setup()

 */

@Override

public void setup() {

super.setup();

alterHierarchy(this.rootNode);

}





/**

 * Recourses the object tree and puts replaces KeyValuePairs as 
attributes in the parent object

 *

 * @param node the node to alter

 */

private void alterHierarchy(final Node node) {

final ListNode children = node.getChildren();

//final ArrayListNode usedChilds = new ArrayList();

MapString, String attributes = node.getAttributes();

for( Node child : children ) {

if( 
KeyValuePair.equalsIgnoreCase(child.getName()) ) {

String key = 
child.getAttributes().get(key);

 

Re: Log4j2 Appender attributes with strict xml config

2013-10-14 Thread Gary Gregory
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#getConfiguration(org.apache.logging.log4j.core.config.ConfigurationFactory.ConfigurationSource)

  */

 @Override

 public Configuration getConfiguration(ConfigurationSource source) 
 {

 return new StrictXMLConfiguration(source);

 }





 /**

  * @see 
 org.apache.logging.log4j.core.config.ConfigurationFactory#getSupportedTypes()

  */

 @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.ConfigurationSource;





 /**

  * Lets the base class {@link XMLConfiguration} do all the hard work and 
 patch the object tree before it is being used by {@link BaseConfiguration}

  *

  * @author a href=mailto:alexander.rat...@materna.de;Alexander 
 Rathai/a

  */

 public class StrictXMLConfiguration extends XMLConfiguration {



 /**

  * @param configSource

  */

 public StrictXMLConfiguration(ConfigurationSource configSource) {

 super(configSource);

 }





 /**

  * @see 
 org.apache.logging.log4j.core.config.XMLConfiguration#setup()

  */

 @Override

 public void setup() {

 super.setup();

 

AW: Log4j2 Appender attributes with strict xml config

2013-10-14 Thread Alexander.Rathai
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 

Re: Log4j2 Appender attributes with strict xml config

2013-10-14 Thread Gary Gregory
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

On Mon, Oct 14, 2013 at 10:25 AM,  alexander.rat...@materna.de wrote:
 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 

Re: Log4j2 Appender attributes with strict xml config

2013-10-14 Thread Ralph Goers

On Oct 14, 2013, at 7:31 AM, Gary Gregory garydgreg...@gmail.com 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.

Ralph
-
To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
For additional commands, e-mail: log4j-user-h...@logging.apache.org



Re: Log4j2 Appender attributes with strict xml config

2013-10-14 Thread Gary Gregory
On Mon, Oct 14, 2013 at 11:10 AM, Ralph Goers
ralph.go...@dslextreme.com wrote:

 On Oct 14, 2013, at 7:31 AM, Gary Gregory garydgreg...@gmail.com 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.org
 For additional commands, e-mail: log4j-user-h...@logging.apache.org




-- 
E-Mail: garydgreg...@gmail.com | ggreg...@apache.org
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.org
For additional commands, e-mail: log4j-user-h...@logging.apache.org



Re: roll over strategy question

2013-10-14 Thread Arkin Yetis
Hi,
I can't seem to get the DefaultRolloverStrategy to work with the following
configuration. Is there anything I am doing wrong?
Thanks,
Arkin

?xml version=1.0 encoding=UTF-8?
configuration status=info name=ABC 
  appenders
RollingFile name=localFile fileName=test.log
filePattern=test-%d{MM-dd-}.log.gz
  PatternLayout pattern=%d{HH:mm:ss.SSS} %-5level %class{36}:%L
%M - %msg%n /
  TimeBasedTriggeringPolicy /
  DefaultRolloverStrategy max=2 /
/RollingFile
  /appenders

  loggers
root level=info
  appender-ref ref=localFile /
/root
  /loggers
/configuration