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.Co nsoleAppen der">
<layout class="org.apache.log4j.Pa tternLayou t">
<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.Da ilyRolling FileAppend er">
<param name="File" value="log/AdapterService. log"/>
<layout class="org.apache.log4j.Pa tternLayou t">
<!-- <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.jd o">
<priority value="warn" />
</category>
<category name="org.exolab.castor.pe rsist">
<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
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.Co
<layout class="org.apache.log4j.Pa
<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.Da
<param name="File" value="log/AdapterService.
<layout class="org.apache.log4j.Pa
<!-- <param name="ConversionPattern" value="%d{dd-MM-yy HH:mm:ss.SSS}[%p][%t][%c{1
<param name="ConversionPattern" value="%d %-5r %-5p [%C{1}] {%t} %m%n"/>
</layout>
</appender>
<category name="org.exolab.castor.jd
<priority value="warn" />
</category>
<category name="org.exolab.castor.pe
<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
ASKER
what about the info?
ASKER
i want to disable the debug logs (all)
i do not want to view them
i do not want to view them
that would be good idea
ASKER
i ll check
ASKER
it does not work, can you give me properties file,
but, i hope it if it was xml
but, i hope it if it was xml
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This log config file it is already used,
because if it is not used the console will give a warning
because if it is not used the console will give a warning
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?
the easyest way is to setLevel from configuration file, how can i do that?
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.Fi leAppender ">
<layout class="org.apache.log4j.Si mpleLayout "/>
</appender>
<root>
<priority value="info" />
<appender-ref ref="myAppender"/>
</root>
</log4j:configuration>
-------------------------- ---------- ---
i used: PropertyConfigurator.confi gure("conf ig-propert ies.xml");
with this code:
import org.apache.log4j.*;
import org.apache.log4j.PropertyC onfigurato r;
public class MyClass {
/* get a static logger instance with name com.foo.sampleapp.MyClass */
static Logger myLogger = Logger.getLogger(MyClass.c lass.getNa me( ));
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(myApp ender);
PropertyConfigurator.confi gure("conf ig-propert ies.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...
-------------------------- ----
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="myAppender"
class="org.apache.log4j.Fi
<layout class="org.apache.log4j.Si
</appender>
<root>
<priority value="info" />
<appender-ref ref="myAppender"/>
</root>
</log4j:configuration>
--------------------------
i used: PropertyConfigurator.confi
with this code:
import org.apache.log4j.*;
import org.apache.log4j.PropertyC
public class MyClass {
/* get a static logger instance with name com.foo.sampleapp.MyClass */
static Logger myLogger = Logger.getLogger(MyClass.c
Appender myAppender;
SimpleLayout myLayout;
/* Constructor */
public MyClass(){
/* Set logger priority level programmatically. Though this is
better done externally */
//myLogger.setLevel(Level.
/* Instantiate a layout and an appender, assign layout to
appender programmatically */
myLayout = new SimpleLayout();
myAppender = new ConsoleAppender(myLayout);
// Interface
/* Assign appender to the logger programmatically */
myLogger.addAppender(myApp
PropertyConfigurator.confi
} //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...
--------------------------
ASKER
it should be like:
import org.apache.log4j.xml.DOMCo nfigurator ;
.
.
.
.
.
DOMConfigurator.configure( "config-pr operties.x ml");
then it will work
import org.apache.log4j.xml.DOMCo
.
.
.
.
.
DOMConfigurator.configure(
then it will work
make it
<priority value="error" />