Return-Path: X-Original-To: apmail-logging-log4j-user-archive@www.apache.org Delivered-To: apmail-logging-log4j-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id D553310E28 for ; Mon, 14 Oct 2013 14:18:10 +0000 (UTC) Received: (qmail 36300 invoked by uid 500); 14 Oct 2013 14:18:10 -0000 Delivered-To: apmail-logging-log4j-user-archive@logging.apache.org Received: (qmail 36069 invoked by uid 500); 14 Oct 2013 14:18:08 -0000 Mailing-List: contact log4j-user-help@logging.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Log4J Users List" Reply-To: "Log4J Users List" Delivered-To: mailing list log4j-user@logging.apache.org Received: (qmail 36046 invoked by uid 99); 14 Oct 2013 14:18:08 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 14 Oct 2013 14:18:08 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of garydgregory@gmail.com designates 209.85.214.48 as permitted sender) Received: from [209.85.214.48] (HELO mail-bk0-f48.google.com) (209.85.214.48) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 14 Oct 2013 14:18:02 +0000 Received: by mail-bk0-f48.google.com with SMTP id my13so2605190bkb.21 for ; Mon, 14 Oct 2013 07:17:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=eytOTHgLEb+BIXVSKzn7uJWsMWiXbkIlksMGOqA8Kos=; b=Bs2MpnxI+kET7lcO2d7q4pEn+e8/jx5B3ni8yGq35+7CjWCRsXFTwJ1gMbdpBULZpk ETS/XQUNkIHEBrNV7tbS/vOidVckJY+9knOWxhrAvAKWyPmzsB9hjQO4F1BQzgVlvEU5 rPHvA/RvmeYr6LpjTCYm9f2HX4/Q5y1aB1ijLqOkYEIG2z7gnmqGVTCvk7Nje2S4vS87 P0y1BtXKC5FZseAaZ9nKr+ptdlzOF5vDiZuyWD7hQxjIaVeq4urnatqhS9d93Akr9qXd ja/tj3LNdlmkwbcqVfQiCxcLRBE0Q6Xn2Ez9dgBvdlGo2iK0JBO1BULw1liiHnOI6ZXR bvUQ== MIME-Version: 1.0 X-Received: by 10.205.65.78 with SMTP id xl14mr30158594bkb.1.1381760262214; Mon, 14 Oct 2013 07:17:42 -0700 (PDT) Received: by 10.205.6.7 with HTTP; Mon, 14 Oct 2013 07:17:42 -0700 (PDT) In-Reply-To: <399C55D178537F4FB31E4F8F6A8AE1ECCD8B8D@mscas.materna.com> References: <399C55D178537F4FB31E4F8F6A8AE1ECCD8B8D@mscas.materna.com> Date: Mon, 14 Oct 2013 10:17:42 -0400 Message-ID: Subject: Re: Log4j2 Appender attributes with strict xml config From: Gary Gregory To: Log4J Users List Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org 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, wrote: > Hi, > I'm using log4j2-beta9 and want to configure it using a log4j2.xml in str= ict mode. My issue is: how do I specify attributes that are not in the ship= ped schema file? An Example: > > status=3D"DEBUG" > strict=3D"true" > monitorInterval=3D"5" > name=3D"TestingAttributes" > verbose=3D"true" > xmlns:xsi=3D"http://www.w3.org/2001/XMLSchema-instance" > xsi:noNamespaceSchemaLocation=3D"Log4j-config.xsd"> > > > > type=3D"Console" > name=3D"SYSERR" > target=3D"SYSTEM_ERR"> > > %date{dd.MM.yyyy HH:mm:ss,SSS} %5p %logger %m%n<= /Pattern> > > > type=3D"MarkerFilter" > marker=3D"FLOW" > onMatch=3D"DENY" > > onMismatch=3D"NEUTRAL" /> > type=3D"MarkerFilter" > marker=3D"EXCEPTION" > onMatch=3D"DENY" > onMismatch=3D"NEUTRAL" /> > > > > > > > > > > Notice that I want to set the appender to have the target SYSTEM_ERR but = the attribute is not allowed in strict mode. > target=3D"SYSTEM_ERR"> > I could always edit the Log4j-config.xsd and allow that attribute there b= ut 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 anyt= hing 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 StrictXMLConfigu= rationFactory} > > * > > * @author Alexander R= athai > > */ > > @Plugin(name =3D "StrictXMLConfigurationFactory", category =3D "Confi= gurationFactory") > > @Order(4) > > public class StrictXMLConfigurationFactory extends ConfigurationFacto= ry { > > > > /** > > * Valid file extensions for XML files. > > */ > > public static final String[] SUFFIXES =3D new String[]{".xml"= }; > > > > > > /** > > * @see org.apache.logging.log4j.core.config.ConfigurationFac= tory#getConfiguration(org.apache.logging.log4j.core.config.ConfigurationFac= tory.ConfigurationSource) > > */ > > @Override > > public Configuration getConfiguration(ConfigurationSource sou= rce) { > > return new StrictXMLConfiguration(source); > > } > > > > > > /** > > * @see org.apache.logging.log4j.core.config.ConfigurationFac= tory#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.Conf= igurationSource; > > > > > > /** > > * Lets the base class {@link XMLConfiguration} do all the hard work = and patch the object tree before it is being used by {@link BaseConfigurati= on} > > * > > * @author Alexander R= athai > > */ > > public class StrictXMLConfiguration extends XMLConfiguration { > > > > /** > > * @param configSource > > */ > > public StrictXMLConfiguration(ConfigurationSource configSourc= e) { > > 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 List children =3D node.getChildren(); > > // final ArrayList usedChilds =3D new ArrayList<= >(); > > Map attributes =3D node.getAttributes= (); > > for( Node child : children ) { > > if( "KeyValuePair".equalsIgnoreCase(child.get= Name()) ) { > > String key =3D child.getAttributes().= get("key"); > > String value =3D child.getValue(); > > attributes.put(key, value); > > // usedChilds.add(child); > > } > > else { > > alterHierarchy(child); > > } > > } > > // children.removeAll(usedChilds); > > } > > } > > > > And i patched the xsd a bit: > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > Then I set the Systemproperty `log4j.configurationFactory` to the fully q= ualified classname of the StrictXMLConfigurationFactory and it works really= well! > > Best Regards, > Alex > > Alexander Rathai > ___________________________________________ > MATERNA GmbH Information & Communications > Vo=C3=9Fkuhle 37 * 44141 Dortmund * Germany > Amtsgericht Dortmund * HRB 5839 > Gesch=C3=A4ftsf=C3=BChrer: Dr. Winfried Materna, Helmut an de Meulen, Ral= ph Hartwig > Tel: +49 (231) 5599-8622 > http://www.materna.de > --=20 E-Mail: garydgregory@gmail.com | ggregory@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-unsubscribe@logging.apache.org For additional commands, e-mail: log4j-user-help@logging.apache.org