Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8783719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:53:44+00:00 2026-06-13T20:53:44+00:00

I want to use the new Log4J 2 – Java Logging Framework. Everything work

  • 0

I want to use the new Log4J 2 – Java Logging Framework. Everything work fine, but I tried since a hour to load a custom configuration file to configure the logging (like log level).

This is my log4j2.xml:

<?xml version="1.0" encoding="UTF-8"?>
<configuration status="OFF">
  <appenders>
    <Console name="Console" target="SYSTEM_OUT">
      <PatternLayout pattern="%d{HH:mm:ss} [%t] %-5level %logger{36} - %msg%n"/>
    </Console>
  </appenders>
  <loggers>
    <root level="error">
      <appender-ref ref="Console"/>
    </root>
  </loggers>
</configuration>

I tried the following, but nothing works:

  • Move the log4j2.xml file so it’s located in the default package.
  • Move the log4j2.xml file anywhere in the project
  • Name the log4j2.xml file as “log4j.xml”
  • Create a folder in your project, place your log4j2.xml file there and add that folder to your runtime classpath

Since the official website can’t help me, I hope you can help me get Log4j 2 working with my configuration file.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T20:53:46+00:00Added an answer on June 13, 2026 at 8:53 pm

    Important: make sure the name of the configuration file is log4j2.xml (note the 2 before the period) as opposed to log4j.xml

    My guess is nothing’s happening because nothing is logged using the error level. You may want to try adding another logger like so:

    <logger name="com.foo.Bar" level="trace">
      <appender-ref ref="Console"/>
    </logger>
    

    Looks like the Configuration section might be a good resource.

    To elaborate further, you’re specifying a logger with the level set to “error”:

    <root level="error">
      <appender-ref ref="Console"/>
    </root>
    

    This means that only the messages logged using Level.ERROR will show up in the log. Adding a logger with a less restrictive level will allow for more messages to appear in the log. I recommend taking a look at the Architecture section of the manual (if you scroll down the page you’ll see the table that explains logging levels). Alternatively, you could just change the level of the root logger to trace (instead of adding a new logger)

    Given the configuration you specified, executing the code below yields something like 13:27:50.244 [main] ERROR com.example.Log4j2Tester - testing ERROR level

    package com.example;
    
    import org.apache.logging.log4j.LogManager;
    import org.apache.logging.log4j.Logger;
    
    public class Log4j2Tester {
        private static final Logger LOG = LogManager.getLogger(Log4j2Tester.class);
    
        public static void main(String[] args) {
            LOG.error("testing ERROR level");
    
    //if you change the level of root logger to 'trace'
    //then you'll also see something like
    //    13:27:50.244 [main] TRACE com.example.Log4j2Tester - exiting application
            LOG.trace("exiting application");
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to use the new combobox control of the Ajax control Toolkit. But
I am new to the structure map but i want to use it in
I want to use new .Net framework 4.0 feature Configuration-Based Activation. I wrote that
I want to use the new java.nio.file.Files.walkFileTree in Scala. And I was even successful:
I am new to log4j but I've been reading for almost an hour, and
I want to use new graph api for invite to events like, EVENT_ID/invited/USER_ID1,USER_ID2 But
I want to use the new MemoryCache class but I am not yet using
I want to use japid-0.9* with my new play application. I already installed japid
I want to use the SqlExpress2008 Bootstrapper for a new installation on Windows7, I
i want to use stripes in our new project. This will take care of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.