Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a sample default config file in YAML for log4j2?

Tags:

yaml

log4j2

The documentation for log4j2 configuration provides a nice sample XML document equivalent to the default configuration:

<?xml version="1.0" encoding="UTF-8"?> <Configuration status="WARN">   <Appenders>     <Console name="Console" target="SYSTEM_OUT">       <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>     </Console>   </Appenders>   <Loggers>     <Root level="error">       <AppenderRef ref="Console"/>     </Root>   </Loggers> </Configuration> 

What would the equivalent file look like as (valid) YAML?

like image 834
sea-rob Avatar asked Jan 23 '15 02:01

sea-rob


People also ask

What is log4j2 configuration file?

Configuration of Log4j 2 can be accomplished in 1 of 4 ways: Through a configuration file written in XML, JSON, YAML, or properties format. Programmatically, by creating a ConfigurationFactory and Configuration implementation.

Where is the log4j2 configuration file?

By default, we'll leave the Log4j2 configuration file (log4j2. xml/log4j2-spring. xml) in the project classpath or resources folder.

Where is the log4j properties file?

The file is named log4j. properties and is located in the $DGRAPH_HOME/dgraph-hdfs-agent/lib directory. The file defines the ROLLINGFILE appenders for the root logger and also sets the log level for the file.


1 Answers

The YAML file

The equivalent YAML file ( log4j2.yaml ) looks like this:

Configuration:   status: warn    Appenders:     Console:       name: Console       target: SYSTEM_OUT       PatternLayout:         Pattern: "%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"    Loggers:     Root:       level: error       AppenderRef:         ref: Console 

This file is automatically loaded (assuming that the file is in the classpath and having the required dependencies), as described in Automatic Configuration.

Maven

If you are using Maven, the following dependencies are required:

<dependency>     <groupId>org.apache.logging.log4j</groupId>     <artifactId>log4j-api</artifactId>     <version>2.1</version> </dependency> <dependency>     <groupId>org.apache.logging.log4j</groupId>     <artifactId>log4j-core</artifactId>     <version>2.1</version> </dependency> <dependency>     <groupId>com.fasterxml.jackson.dataformat</groupId>     <artifactId>jackson-dataformat-yaml</artifactId>     <version>2.5.0</version> </dependency> 

Imgur

like image 140
Paul Vargas Avatar answered Oct 11 '22 13:10

Paul Vargas