JPT
JPT

Reputation: 555

log4j2.configurationFile does not accept yaml?

I migrated my old project from some SimpleLogger to Log4J. I hate Log4j because it is extremely difficult to set up.

Now, how do I feed some config into it?

Configuration:
  status:info
  name: YAMLConfigTest
  thresholdFilter:
    level: info
  Appenders:
    Console:
      name: STDOUT
      target: SYSTEM_OUT
      PatternLayout:
        Pattern: "%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"

I tried loading it using the log4j2.configurationFile variable. But log4j always tries to interpret the file as XML. Why is that? Is there anything that I can do about it?

ERROR StatusLogger Error parsing /fullpath/log4j2.yaml
 org.xml.sax.SAXParseException; systemId: file:///fullpath/log4j2.yaml; lineNumber: 1; columnNumber: 1; Content ist nicht zulässig in Prolog.
    at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:257)
...
    at org.apache.logging.log4j.LogManager.getContext(LogManager.java:196)
    at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:599)
    at de.tisje.dendro.plot.swing.Kurvenplot.<clinit>(Kurvenplot.java:91)

Alternative solution would be to put the file somewhere where it can be found automatically. Where do I put the file in a standard eclipse/gradle project? do I have to tell gradle how to handle it?

thanks

Upvotes: 1

Views: 763

Answers (1)

Piotr P. Karwasz
Piotr P. Karwasz

Reputation: 16045

The XML ConfigurationFactory is a "catch-all" factory: it tries to read those files that were rejected by other configuration factories.

While the YAML configuration factory is distributed with log4j-core, it requires additional runtime dependencies to be active (this is mentioned briefly in the documentation). You need to add jackson-dataformat-yaml to your project.

Upvotes: 1

Related Questions