Lohg4j2 Schema Errors

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Lohg4j2 Schema Errors

Ed Zappulla
I'm having trouble getting my log4j2.xml file to conform to the schema.
Without the schema specification I don't have any errors but with it in
place I am getting:

cvc-complex-type.2.4.d: Invalid content was found starting with element
'File'. No child element is expected at

 this point.

 

cvc-complex-type.2.4.d: Invalid content was found starting with element
'Logger'. No child element is expected

 at this point.

 

The logging works fine without the schema but Eclipse is warning that its
missing so I would like to have it in place. This is the log4j2.xml file I'm
using:

<?xml version="1.0" encoding="UTF-8"?>
 
<Configuration strict="true"
           xmlns="http://logging.apache.org/log4j/2.0/config"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://logging.apache.org/log4j/2.0/config 
 
https://raw.githubusercontent.com/apache/logging-log4j2/log4j-2.11.1/log4j-c
ore/src/main/resources/Log4j-config.xsd">
 
  <Appenders>
 
    <Console name="console" target="SYSTEM_OUT">
      <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss z} %-5p %-5level -
%msg%n"/>
    </Console>
 
    <File name="file" fileName="mylogfile.log" append="true">
      <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss z} %-5p %-5level -
%msg%n"/>
    </File >
  </Appenders>
 
 
  <Loggers>
    <Root level="DEBUG">
      <AppenderRef ref="console"/>
      <AppenderRef ref="file"/>
    </Root>
 
    <Logger name="org.apache.http" level="WARN" additivity="false">
      <AppenderRef ref="console"/>
      <AppenderRef ref="file"/>
    </Logger>
 
    <Logger name="net.authorize.util" level="WARN" additivity="false">
      <AppenderRef ref="console"/>
      <AppenderRef ref="file"/>
    </Logger>
 
    <Logger name="net.authorize.api" level="WARN" additivity="false">
      <AppenderRef ref="console"/>
      <AppenderRef ref="file"/>
    </Logger>
 
  </Loggers>
 
</Configuration>

 

 

Any help would be appreciated.

 

 

Thank you

 

.ed

 

 

Reply | Threaded
Open this post in threaded view
|

Re: Lohg4j2 Schema Errors

Eric Schwarzenbach
I'm not up on what the state of the log4j config schema is (though I've
seen things in the past about it not being able to model what can
actually be in a config, but these may have been addressed) but by
looking at that xsd, it looks like it wants the Console element to
appear *after* all of the other Appender elements. However even fixing
that, I can't see how your config xml (or mine for that matter) would
validate since that xsd doesn't define the specific appender elements
like File or RollingFile*. *

I could imagine these elements might be meant to be defined by other xsd
files. It is possible to specify multiple xsd files in an xml file, all
of which could be necessary to validate it. (This isn't very commonly
done, but might be a desirable way to do it if various appenders were
condered extensions that the core schema should not "know" about.) So it
might be worth trying to find if there are additional xsd files...



On 1/3/19 8:41 AM, Ed Zappulla wrote:

> I'm having trouble getting my log4j2.xml file to conform to the schema.
> Without the schema specification I don't have any errors but with it in
> place I am getting:
>
> cvc-complex-type.2.4.d: Invalid content was found starting with element
> 'File'. No child element is expected at
>
>   this point.
>
>  
>
> cvc-complex-type.2.4.d: Invalid content was found starting with element
> 'Logger'. No child element is expected
>
>   at this point.
>
>  
>
> The logging works fine without the schema but Eclipse is warning that its
> missing so I would like to have it in place. This is the log4j2.xml file I'm
> using:
>
> <?xml version="1.0" encoding="UTF-8"?>
>  
> <Configuration strict="true"
>             xmlns="http://logging.apache.org/log4j/2.0/config"
>             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>             xsi:schemaLocation="http://logging.apache.org/log4j/2.0/config
>  
> https://raw.githubusercontent.com/apache/logging-log4j2/log4j-2.11.1/log4j-c
> ore/src/main/resources/Log4j-config.xsd">
>  
>    <Appenders>
>  
>      <Console name="console" target="SYSTEM_OUT">
>        <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss z} %-5p %-5level -
> %msg%n"/>
>      </Console>
>  
>      <File name="file" fileName="mylogfile.log" append="true">
>        <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss z} %-5p %-5level -
> %msg%n"/>
>      </File >
>    </Appenders>
>  
>  
>    <Loggers>
>      <Root level="DEBUG">
>        <AppenderRef ref="console"/>
>        <AppenderRef ref="file"/>
>      </Root>
>  
>      <Logger name="org.apache.http" level="WARN" additivity="false">
>        <AppenderRef ref="console"/>
>        <AppenderRef ref="file"/>
>      </Logger>
>  
>      <Logger name="net.authorize.util" level="WARN" additivity="false">
>        <AppenderRef ref="console"/>
>        <AppenderRef ref="file"/>
>      </Logger>
>  
>      <Logger name="net.authorize.api" level="WARN" additivity="false">
>        <AppenderRef ref="console"/>
>        <AppenderRef ref="file"/>
>      </Logger>
>  
>    </Loggers>
>  
> </Configuration>
>
>  
>
>  
>
> Any help would be appreciated.
>
>  
>
>  
>
> Thank you
>
>  
>
> .ed
>
>  
>
>  
>
>

Reply | Threaded
Open this post in threaded view
|

Re: Lohg4j2 Schema Errors

Ralph Goers
In reply to this post by Ed Zappulla
You have specified strict=“true” but then not followed the format required when that attribute is specified. See the example at https://logging.apache.org/log4j/2.x/manual/configuration.html#Configuration_Syntax under the sentence that reads "Below is a sample configuration using the strict format.”

Note that individual Filters, Appenders, Layouts, etc. can have attributes or children that the XML schema doesn’t know anything about and won’t really validate.

Ralph



> On Jan 3, 2019, at 6:41 AM, Ed Zappulla <[hidden email]> wrote:
>
> I'm having trouble getting my log4j2.xml file to conform to the schema.
> Without the schema specification I don't have any errors but with it in
> place I am getting:
>
> cvc-complex-type.2.4.d: Invalid content was found starting with element
> 'File'. No child element is expected at
>
> this point.
>
>
>
> cvc-complex-type.2.4.d: Invalid content was found starting with element
> 'Logger'. No child element is expected
>
> at this point.
>
>
>
> The logging works fine without the schema but Eclipse is warning that its
> missing so I would like to have it in place. This is the log4j2.xml file I'm
> using:
>
> <?xml version="1.0" encoding="UTF-8"?>
>
> <Configuration strict="true"
>           xmlns="http://logging.apache.org/log4j/2.0/config"
>           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>           xsi:schemaLocation="http://logging.apache.org/log4j/2.0/config 
>
> https://raw.githubusercontent.com/apache/logging-log4j2/log4j-2.11.1/log4j-c
> ore/src/main/resources/Log4j-config.xsd">
>
>  <Appenders>
>
>    <Console name="console" target="SYSTEM_OUT">
>      <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss z} %-5p %-5level -
> %msg%n"/>
>    </Console>
>
>    <File name="file" fileName="mylogfile.log" append="true">
>      <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss z} %-5p %-5level -
> %msg%n"/>
>    </File >
>  </Appenders>
>
>
>  <Loggers>
>    <Root level="DEBUG">
>      <AppenderRef ref="console"/>
>      <AppenderRef ref="file"/>
>    </Root>
>
>    <Logger name="org.apache.http" level="WARN" additivity="false">
>      <AppenderRef ref="console"/>
>      <AppenderRef ref="file"/>
>    </Logger>
>
>    <Logger name="net.authorize.util" level="WARN" additivity="false">
>      <AppenderRef ref="console"/>
>      <AppenderRef ref="file"/>
>    </Logger>
>
>    <Logger name="net.authorize.api" level="WARN" additivity="false">
>      <AppenderRef ref="console"/>
>      <AppenderRef ref="file"/>
>    </Logger>
>
>  </Loggers>
>
> </Configuration>
>
>
>
>
>
> Any help would be appreciated.
>
>
>
>
>
> Thank you
>
>
>
> .ed
>
>
>
>
>

Reply | Threaded
Open this post in threaded view
|

RE: Lohg4j2 Schema Errors

Ed Zappulla
Thanks for the help to everyone;  I also received a similar response on
Stack Overflow.  Below is the corrected xml file that will validate.  The
one item I can't seem to specify is the max file size for the file appender
(its not a rolling appender).  

1.      The schema does not have an Appender called File defined a type of
File is used.

2.      The schema defines that the Root node occurs after all the Logger
nodes

<?xml version="1.0" encoding="UTF-8"?>

 

<Configuration strict="true"

           xmlns="http://logging.apache.org/log4j/2.0/config"

           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

           xsi:schemaLocation="http://logging.apache.org/log4j/2.0/config

 
https://raw.githubusercontent.com/apache/logging-log4j2/log4j-2.11.1/log4j-c
ore/src/main/resources/Log4j-config.xsd">

       <Appenders>

             <Appender type="File" name="file" fileName="mylogfile.log">

              <Layout type="PatternLayout" pattern="%d{yyyy-MM-dd HH:mm:ss
z} %-5level - %msg%n" />

         </Appender>

   

              <Appender type="Console" name="console">

              <Layout type="PatternLayout" pattern="%d{yyyy-MM-dd HH:mm:ss
z} %-5level - %msg%n" />

              </Appender>

      </Appenders>

 

 

      <Loggers>

           <Logger name="org.apache.http" level="WARN" additivity="false">

             <AppenderRef ref="console"/>

             <AppenderRef ref="file"/>

           </Logger>

       

           <Logger name="net.authorize.util" level="WARN"
additivity="false">

             <AppenderRef ref="console"/>

             <AppenderRef ref="file"/>

           </Logger>

       

           <Logger name="net.authorize.api" level="WARN" additivity="false">

             <AppenderRef ref="console"/>

             <AppenderRef ref="file"/>

           </Logger>

       

           <Logger name="com.amazonaws" level="WARN" additivity="false">

             <AppenderRef ref="console"/>

             <AppenderRef ref="file"/>

           </Logger>

       

           <Root level="DEBUG">

             <AppenderRef ref="console"/>

             <AppenderRef ref="file"/>

           </Root>

       </Loggers>

 

</Configuration>

 

 

Thank you

 

.ed

 

Ed Zappulla

 

BSG Systems, LLC

17 Red Tail Hawk Ct

Annandale, NJ 08801

 

Mobile: (908) 246-5304

Email: [hidden email]

 

 

-----Original Message-----
From: Ralph Goers [mailto:[hidden email]]
Sent: Friday, January 04, 2019 12:42 AM
To: Log4J Users List <[hidden email]>
Subject: Re: Lohg4j2 Schema Errors

 

You have specified strict= true  but then not followed the format required
when that attribute is specified. See the example at
<https://logging.apache.org/log4j/2.x/manual/configuration.html#Configuratio
n_Syntax>
https://logging.apache.org/log4j/2.x/manual/configuration.html#Configuration
_Syntax under the sentence that reads "Below is a sample configuration using
the strict format.

 

Note that individual Filters, Appenders, Layouts, etc. can have attributes
or children that the XML schema doesn t know anything about and won t really
validate.

 

Ralph

 

 

 

> On Jan 3, 2019, at 6:41 AM, Ed Zappulla <
<mailto:[hidden email]> [hidden email]> wrote:

>

> I'm having trouble getting my log4j2.xml file to conform to the schema.

> Without the schema specification I don't have any errors but with it

> in place I am getting:

>

> cvc-complex-type.2.4.d: Invalid content was found starting with

> element 'File'. No child element is expected at

>

> this point.

>

>

>

> cvc-complex-type.2.4.d: Invalid content was found starting with

> element 'Logger'. No child element is expected

>

> at this point.

>

>

>

> The logging works fine without the schema but Eclipse is warning that

> its missing so I would like to have it in place. This is the

> log4j2.xml file I'm

> using:

>

> <?xml version="1.0" encoding="UTF-8"?>

>

> <Configuration strict="true"

>           xmlns=" <http://logging.apache.org/log4j/2.0/config>
http://logging.apache.org/log4j/2.0/config"

>           xmlns:xsi=" <http://www.w3.org/2001/XMLSchema-instance>
http://www.w3.org/2001/XMLSchema-instance"

>          

> xsi:schemaLocation="http://logging.apache.org/log4j/2.0/config

>

>  <https://raw.githubusercontent.com/apache/logging-log4j2/log4j-2.11.1/l>
https://raw.githubusercontent.com/apache/logging-log4j2/log4j-2.11.1/l

> og4j-c ore/src/main/resources/Log4j-config.xsd">

>

>  <Appenders>

>

>    <Console name="console" target="SYSTEM_OUT">

>      <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss z} %-5p %-5level -

> %msg%n"/>

>    </Console>

>

>    <File name="file" fileName="mylogfile.log" append="true">

>      <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss z} %-5p %-5level -

> %msg%n"/>

>    </File >

>  </Appenders>

>

>

>  <Loggers>

>    <Root level="DEBUG">

>      <AppenderRef ref="console"/>

>      <AppenderRef ref="file"/>

>    </Root>

>

>    <Logger name="org.apache.http" level="WARN" additivity="false">

>      <AppenderRef ref="console"/>

>      <AppenderRef ref="file"/>

>    </Logger>

>

>    <Logger name="net.authorize.util" level="WARN" additivity="false">

>      <AppenderRef ref="console"/>

>      <AppenderRef ref="file"/>

>    </Logger>

>

>    <Logger name="net.authorize.api" level="WARN" additivity="false">

>      <AppenderRef ref="console"/>

>      <AppenderRef ref="file"/>

>    </Logger>

>

>  </Loggers>

>

> </Configuration>

>

>

>

>

>

> Any help would be appreciated.

>

>

>

>

>

> Thank you

>

>

>

> .ed

>

>

>

>

>