[java] How do you Change a Package's Log Level using Log4j?

I've encountered the following bug:

http://issues.apache.org/jira/browse/AXIS2-4363

It states the following:

This error only occurs when log level for org.apache.axiom is DEBUG so a workaround is to set log level > DEBUG.

My question is HOW do I go about doing that? I've been scouring my directories for a properties file or something and I've been looking to see if there was something I could set in code, but I really have no idea what I'm doing. I'm running a console app on my desktop right now while trying to get this to work.

Update 1: I noticed that my Axis2 directory has its own log4j.properties file in its root. Is this safely ignored or is it part of the solution (or part of the problem)?

Update 2: The root level log4j.properties file is apprently not set correctly. Right now it looks like this:

log4j.rootLogger=DEBUG, R 
log4j.logger.org.apache.axiom=WARN
log4j.appender.R=org.apache.log4j.RollingFileAppender 
log4j.appender.R.MaxFileSize=10MB 
log4j.appender.R.MaxBackupIndex=10 
log4j.appender.R.layout=org.apache.log4j.PatternLayout 
log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n

but that is apparently wrong as this code returns "Log level is null":

System.out.println("Log level is " + logger.getLevel());

For now I am setting the log level in code using

Logger logger = Logger.getLogger("org.apache.axiom");
logger.setLevel(Level.WARN);

This question is related to java logging log4j axis2 axiom

The answer is


set the system property log4j.debug=true. Then you can determine where your configuration is running amuck.


This work for my:

log4j.logger.org.hibernate.type=trace

Also can try:

log4j.category.org.hibernate.type=trace

I encountered the exact same problem today, Ryan.

In my src (or your root) directory, my log4j.properties file now has the following addition

# https://issues.apache.org/jira/browse/AXIS2-4363
log4j.category.org.apache.axiom=WARN

Thanks for the heads up as to how to do this, Benjamin.


I just encountered the issue and couldn't figure out what was going wrong even after reading all the above and everything out there. What I did was

  1. Set root logger level to WARN
  2. Set package log level to DEBUG

Each logging implementation has it's own way of setting it via properties or via code(lot of help available on this)

Irrespective of all the above I would not get the logs in my console or my log file. What I had overlooked was the below...


enter image description here


All I was doing with the above jugglery was controlling only the production of the logs(at root/package/class etc), left of the red line in above image. But I was not changing the way displaying/consumption of the logs of the same, right of the red line in above image. Handler(Consumption) is usually defaulted at INFO, therefore your precious debug statements wouldn't come through. Consumption/displaying is controlled by setting the log levels for the Handlers(ConsoleHandler/FileHandler etc..) So I went ahead and set the log levels of all my handlers to finest and everything worked.

This point was not made clear in a precise manner in any place.

I hope someone scratching their head, thinking why the properties are not working will find this bit helpful.


Examples related to java

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How much should a function trust another function How to implement a simple scenario the OO way Two constructors How do I get some variable from another class in Java? this in equals method How to split a string in two and store it in a field How to do perspective fixing? String index out of range: 4 My eclipse won't open, i download the bundle pack it keeps saying error log

Examples related to logging

How to redirect docker container logs to a single file? Console logging for react? Hide strange unwanted Xcode logs Where are logs located? Retrieve last 100 lines logs Spring Boot - How to log all requests and responses with exceptions in single place? How do I get logs from all pods of a Kubernetes replication controller? Where is the Docker daemon log? How to log SQL statements in Spring Boot? How to do logging in React Native?

Examples related to log4j

No log4j2 configuration file found. Using default configuration: logging only errors to the console How to stop INFO messages displaying on spark console? What is log4j's default log file dumping path How to give environmental variable path for file appender in configuration file in log4j No appenders could be found for logger(log4j)? SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". in a Maven Project log4j:WARN No appenders could be found for logger (running jar file, not web app) Error: "setFile(null,false) call failed" when using log4j java.lang.ClassNotFoundException: org.apache.log4j.Level How can I create 2 separate log files with one log4j config file?

Examples related to axis2

ORA-12516, TNS:listener could not find available handler The endpoint reference (EPR) for the Operation not found is Content is not allowed in Prolog SAXParserException Java Webservice Client (Best way) How do you Change a Package's Log Level using Log4j? Difference between Apache CXF and Axis

Examples related to axiom

How do you Change a Package's Log Level using Log4j?