Link to home
Start Free TrialLog in
Avatar of isaihat
isaihat

asked on

Log4j: how to Disable info and debug levels logs through configuration file

Hi guys,

i have this XML config file:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

<log4j:configuration>
       
    <appender name="console" class="org.apache.log4j.ConsoleAppender">
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d{dd-MM-yy HH:mm:ss.SSS}-%p-%C-%t- %m%n"/>
        </layout>
    </appender>
   

    <appender name="AccountActivation" class="org.apache.log4j.DailyRollingFileAppender">
        <param name="File" value="log/AdapterService.log"/>
        <layout class="org.apache.log4j.PatternLayout">

         <!--   <param name="ConversionPattern" value="%d{dd-MM-yy HH:mm:ss.SSS}[%p][%t][%c{1}]- %m%n"/> -->
      <param name="ConversionPattern" value="%d %-5r %-5p [%C{1}] {%t} %m%n"/>
        </layout>
  </appender>  


    <category name="org.exolab.castor.jdo">
      <priority value="warn" />
    </category>

    <category name="org.exolab.castor.persist">
      <priority value="warn" />
    </category>


    <root>
        <priority value="debug" />      
        <appender-ref ref="AccountActivation"/>
    </root>

</log4j:configuration>


using this file, how can i disable the INFO and DEBUG to appear in logs,

and not allow any of them to be viewed

where i do not want to change the orginal code


best regads,
isaihat
Avatar of Ajay-Singh
Ajay-Singh

> <priority value="debug" />
make it

<priority value="error" />
Avatar of isaihat

ASKER

what about the info?
Avatar of isaihat

ASKER

i want to disable the debug logs (all)
i do not want to view them
that would be good idea
Avatar of isaihat

ASKER

i ll check
Avatar of isaihat

ASKER

it does not work, can you give me properties file,

but, i hope it if it was xml
ASKER CERTIFIED SOLUTION
Avatar of Ajay-Singh
Ajay-Singh

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of isaihat

ASKER

This log config file it is already used,

because if it is not used the console will give a warning

Avatar of isaihat

ASKER

i set the configurarion, but does not work with it,

the easyest way is to  setLevel from configuration file, how can i do that?
Avatar of isaihat

ASKER

Please look to another example which is easier:
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">

    <appender name="myAppender"
              class="org.apache.log4j.FileAppender">
        <layout class="org.apache.log4j.SimpleLayout"/>
    </appender>

    <root>
        <priority value="info" />
        <appender-ref ref="myAppender"/>
    </root>
</log4j:configuration>

---------------------------------------
i used: PropertyConfigurator.configure("config-properties.xml");
 with this code:
import org.apache.log4j.*;
import org.apache.log4j.PropertyConfigurator;


public class MyClass {

      /* get a static logger instance with name com.foo.sampleapp.MyClass   */
      static Logger myLogger = Logger.getLogger(MyClass.class.getName( ));
      Appender myAppender;
      SimpleLayout myLayout;
      
      
      /* Constructor */
      public MyClass(){
          
            /* Set logger priority level programmatically. Though this is
               better done externally  */
            //myLogger.setLevel(Level.INFO);
               
            /* Instantiate a layout and an appender, assign layout to
               appender programmatically */
            myLayout = new SimpleLayout();
            myAppender = new ConsoleAppender(myLayout);    // Appender is
                                                           // Interface
               
            /* Assign appender to the logger programmatically */
            myLogger.addAppender(myAppender);
          
          
            PropertyConfigurator.configure("config-properties.xml");
      } //end constructor
      
      public void do_something( int a, float b){
             Object x = null;
            /* This log request enabled and log statement logged, since
               INFO = INFO */
            myLogger.info("The values of parameters passed to method do_something are: " + a +","+ b);
               
            /* this log request is not enabled, since DEBUG < INFO*/
               myLogger.debug("Operation performed successfully");
               
            if (x == null){
                  /* this log request is enabled and log statement logged, since
                     ERROR > INFO*/
                  myLogger.error("Value of X is null");
            
            }
      }    //end do_something()
      
      public static void main(String [] args){
            MyClass my = new MyClass();
            my.do_something(3, 6F);
      }

}    // end class MyClass


but still the output include the debug as:
-----------------------------
INFO - The values of parameters passed to method do_something are: 3,6.0
DEBUG - Operation performed successfully
ERROR - Value of X is null
Press any key to continue...
------------------------------
Avatar of isaihat

ASKER

it should be like:
import org.apache.log4j.xml.DOMConfigurator;
.

.
.
.
.
DOMConfigurator.configure("config-properties.xml");

then it will work