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 8678103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:37:38+00:00 2026-06-12T20:37:38+00:00

I want to ask something on log4j. I have this config file for log4j

  • 0

I want to ask something on log4j. I have this config file for log4j on activemq. My problem is that I want to log all INFO level messages from every class I have, but I want to log all DEBUG level messages from “TransportConnection” class to a different file and, at the same time, log all only messages that are greater or equal to WARN level, to the rootLogger.

The problem with this configuration is that I log INFO level messages from “TransportConnection” class in the rootLogger. I want to pass only the WARN and above level to the rootLogger.

I dont want to set a Threshold to the “out” appender, because I want INFO level messages from other classes.

log4j.rootLogger=INFO,out

# Log these warnings
log4j.logger.org.apache.activemq.broker.BrokerRegistry=INFO
log4j.logger.org.apache.activemq.broker.TransportConnection=DEBUG,tc

# Standard logging
log4j.appender.out=org.apache.log4j.RollingFileAppender
log4j.appender.out.file=/var/lib/activemq/log/activemq.log
log4j.appender.out.maxFileSize=10240KB
log4j.appender.out.maxBackupIndex=100
log4j.appender.out.append=true
log4j.appender.out.layout=org.apache.log4j.PatternLayout
log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n

# Transport Connections logging
log4j.appender.tc=org.apache.log4j.RollingFileAppender
log4j.appender.tc.file=/var/lib/activemq/log/tc.log
log4j.appender.tc.maxFileSize=10240KB
log4j.appender.tc.maxBackupIndex=100
log4j.appender.tc.append=true
log4j.appender.tc.layout=org.apache.log4j.PatternLayout
log4j.appender.tc.layout.ConversionPattern=%d [%t] %-5p %-30.30c{1} - %m%n
  • 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-12T20:37:41+00:00Added an answer on June 12, 2026 at 8:37 pm

    You could write your own custom filter. I suggest that implementation could be something like that:

    public class MinLevelForParticularClassFilter extends Filter {
    
        private boolean acceptOnMatch = false;
        private Level level;
        private String className;
    
        @Override
        public int decide(LoggingEvent event) {
            if (this.className != null && this.level != null) {
                if (event.getLocationInformation().getClassName().startsWith(className)) {
                    // this is event for specified class
                    if (!event.getLevel().isGreaterOrEqual(this.level)) {
                        // level of event is less than specified level
                        return Filter.DENY;
                    }
                }
            }
    
            if (acceptOnMatch) {
                return Filter.ACCEPT;
            } else {
                return Filter.NEUTRAL;
            }
        }
    
        public boolean isAcceptOnMatch() { return acceptOnMatch; }
        public void setAcceptOnMatch(boolean acceptOnMatch) { this.acceptOnMatch = acceptOnMatch; }
    
        public Level getLevel() { return level; }
        public void setLevel(Level level) { this.level = level; }
    
        public String getClassName() { return className; }
        public void setClassName(String className) { this.className = className; }
    }
    

    Note that if you change “className” variable to “packageName” variable, the implementation will be the same for filter by particular package.

    The log4j configuration in XML (since filters are unsupported by configuration in property files):

    <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
        <appender name="out" class="org.apache.log4j.RollingFileAppender">
            <param name="File" value="activemq.log" /> 
            <param name="MaxFileSize" value="10240KB" />
            <param name="MaxBackupIndex" value="100" />
            <param name="Append" value="true" />
            <layout class="org.apache.log4j.PatternLayout">
                <param name="ConversionPattern" value="%d [%-15.15t] %-5p %-30.30c{1} - %m%n"/> 
            </layout>
    
            <!-- Apply filter to appender that's destined for root logger -->
            <filter class="com.foo.log4j.filters.MinLevelForParticularClassFilter">
                <param name="Level" value="WARN" />
                <param name="ClassName" value="org.apache.activemq.broker.TransportConnection" />
                <param name="AcceptOnMatch" value="true" />
            </filter>
    
        </appender>
    
        <appender name="tc" class="org.apache.log4j.RollingFileAppender">
            <param name="File" value="tc.log" /> 
            <param name="MaxFileSize" value="10240KB" />
            <param name="MaxBackupIndex" value="100" />
            <param name="Append" value="true" />
            <layout class="org.apache.log4j.PatternLayout">
                <param name="ConversionPattern" value="%d [%t] %-5p %-30.30c{1} - %m%n"/> 
            </layout>
        </appender>
    
        <logger name="org.apache.activemq.broker.BrokerRegistry">
            <level value="INFO" />
        </logger>
        <logger name="org.apache.activemq.broker.TransportConnection">
            <level value="DEBUG" />
            <appender-ref ref="tc" />
        </logger>
        <root> 
            <priority value ="INFO" /> 
            <appender-ref ref="out" /> 
        </root> 
    </log4j:configuration>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am not even sure how to ask this question. I want something that
I want to ask about this problem. I have a movieclip (instance name :
I want to ask a question that i have a master template like this
I just want to ask if anybody has done something like this. Basically, it's
I want to ask, can you do something similar to this? Event += eventInstance;
hihi i have a question that i want to ask about c# and window
Possible Duplicate: Javascript scoping variables theory Hi all, I want to ask something stranger.
I want to ask you something i'm doing like that .. LinkedBlockingQueue<Whatch_Directory> queue =
Hello guys, just want you to ask something about my code... I have 5
I want to ask something, what makes a difference in the output below that

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.