DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Surviving the Incident
  • Detect Log4j Vulnerability Using ACS
  • How To Detect and Secure Your Java App From Log4j Vulnerabilities
  • How to Check if a Java Project Depends on A Vulnerable Version of Log4j

Trending

  • Stop Running Two Data Systems for One Agent Query
  • Architecting an Embedded Efficiency Layer: A Platform Deep Dive into Day-Two Operational Tuning
  • From APIs to Actions: Rethinking Back-End Design for Agents
  • Product-Led Software Delivery: Intelligent Platforms for DevOps at Scale
  1. DZone
  2. Coding
  3. Java
  4. Configuring log4j Loggers to Ignore Spring/Hibernate Logging

Configuring log4j Loggers to Ignore Spring/Hibernate Logging

By 
Faheem Sohail user avatar
Faheem Sohail
·
Aug. 05, 13 · Interview
Likes (1)
Comment
Save
Tweet
Share
14.8K Views

Join the DZone community and get the full member experience.

Join For Free

If you use log4j with your project that also uses Spring framework and/or hibernate or any other framework, and you would feel the need to set different Log levels for your own code and for third party components, you may also want different log levels for your own components. The answer is simple. Configure different loggers for different package names and provide different log levels for each. For example, lets take a look at the following log4j XML

<?xml version="1.0" encoding="UTF-8"?>
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
   <appender name="CA">
      <layout>
         <param name="ConversionPattern" value="%-4r [%t] %-5p %c %x - %m%n" />
      </layout>
   </appender>
   <appender name="FA">
      <param name="File" value="output.log" />
      <param name="Threshold" value="WARN" />
      <layout>
         <param name="ConversionPattern" value="%-4r [%t] %-5p %c %x - %m%n" />
      </layout>
   </appender>
   <logger name="org.springframework">
      <level value="ERROR" />
   </logger>
   <root>
      <level value="INFO" />
      <appender-ref ref="CA" />
      <appender-ref ref="FA" />
   </root>
</log4j:configuration>

In the logger tag, specify the package name/prefix/regex and then specify the log level. The following logger will output only logs of level ERROR and above for packages starting with org.springframework

<logger name="org.springframework">
   <level value="ERROR" />
</logger>
Log4j

Published at DZone with permission of Faheem Sohail. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Surviving the Incident
  • Detect Log4j Vulnerability Using ACS
  • How To Detect and Secure Your Java App From Log4j Vulnerabilities
  • How to Check if a Java Project Depends on A Vulnerable Version of Log4j

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook