How to disable log call paths

I would like to disable the part of log4j that registers all class / method calls that are called. For instance...

Apr 15, 2013 10:50:52 AM com.production.tasks.ImportNewOrders checkForOrders INFO: ------- Order #295510 Hibernate: select asset0_.id as id0_, asset0_.AssetID as AssetID0_, asset0_.barcode as barcode0_, asset0_.filename as filename0_, asset0_.orderID as orderID0_, asset0_.Priority as Priority0_, asset0_.qty as qty0_, asset0_.Status as Status0_, asset0_.TimeStamp_Received as TimeStamp9_0_, asset0_.type as type0_, asset0_.URL_Thumb as URL11_0_, asset0_.vendor as vendor0_ from production_queue.3D_Mgmt_v1_Assets asset0_ where asset0_.AssetID=? Apr 15, 2013 10:51:04 AM com.production.utility.File download INFO: - DecoFile downloaded from https://secure-url/165054548?user[id]=xxxxx&key=xxxx to th_1107461838.png Apr 15, 2013 10:51:17 AM com.production.utility.File download INFO: - DecoFile downloaded from https://secure-url/165054548?user[id]=xxxxx&key=xxxx to 1107461838.png Hibernate: insert into production_queue.3D_Mgmt_v1_Assets (AssetID, barcode, filename, orderID, Priority, qty, Status, TimeStamp_Received, type, URL_Thumb, vendor) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) Apr 15, 2013 10:51:17 AM com.production.tasks.ImportNewOrders checkForOrders 

I want to be...

 INFO: ------- Order #295510 Hibernate: select asset0_.id as id0_, asset0_.AssetID as AssetID0_, asset0_.barcode as barcode0_, asset0_.filename as filename0_, asset0_.orderID as orderID0_, asset0_.Priority as Priority0_, asset0_.qty as qty0_, asset0_.Status as Status0_, asset0_.TimeStamp_Received as TimeStamp9_0_, asset0_.type as type0_, asset0_.URL_Thumb as URL11_0_, asset0_.vendor as vendor0_ from production_queue.3D_Mgmt_v1_Assets asset0_ where asset0_.AssetID=? INFO: - DecoFile downloaded from https://secure-url/165054548?user[id]=xxxxx&key=xxxx to th_1107461838.png INFO: - DecoFile downloaded from https://secure-url/165054548?user[id]=xxxxx&key=xxxx to 1107461838.png Hibernate: insert into production_queue.3D_Mgmt_v1_Assets (AssetID, barcode, filename, orderID, Priority, qty, Status, TimeStamp_Received, type, URL_Thumb, vendor) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) 

Currently, I have not configured the log4j properties file. I want INFO to go to stdout as it is, but just avoid these method call logs.

Update

Since then I created the log4j.properties file, but I can not find any settings to turn off registration of method calls.

Note; I am not trying to change the "format" of the log messages, but completely disable method call logging.

 log4j.rootLogger=INFO, stdout log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %t %c:%L - %m%n #prevent "no appenders" warning despite having appenders - http://stackoverflow.com/a/15912258/197606 log4j.category.org.jboss.logging=INFO, stdout #log4j.category.org.springframework=DEBUG,stdout log4j.category.com.model.entity =DEBUG,stdout 
+4
source share
3 answers

These are not log4j calls. What you see is the default java.util.logging template (for stderr). Therefore, you need to configure java.util.logging correctly. See http://tutorials.jenkov.com/java-logging/configuration.html

+2
source

If you use PatternLayout to customize your Appender, you must remove %l , which returns a call method using a fully quallified name. Your layout should look something like this:

 PatternLayout layout = new PatternLayout("%-5p %m");//Level and Message 

But I recommend putting some kind of timestamp with one of this:

%d{dd MMM yyyy HH:mm:ss,SSS}

+1
source

If you do not have to configure the log4j properties file from the outside, then some component in your application programmatically configures it. In any case, you need to override any current configuration that you are currently using with what you really want. The easiest and most convenient way to do this is to create a valid properties file and put it in your class path. This will allow you not only to redefine the configuration of existing registrars, but also to define new ones.

If necessary, you can also programmatically change the configuration of Log4J. The easiest way to do this is with a static initializer in the launch class. A simple example:

 public class LogTest { private static final Logger logger = Logger.getLogger(LogTest.class); static { Logger.getRootLogger().getLoggerRepository().resetConfiguration(); ConsoleAppender console = new ConsoleAppender(); console.setLayout(new PatternLayout("%-5p %m%n")); console.setThreshold(Level.TRACE); console.activateOptions(); Logger.getRootLogger().addAppender(console); } @Test public void testLogging() throws Exception { logger.info("I am a simplistic info log message"); logger.error("I am a simplistic error log message", new IllegalArgumentException()); } } 
+1
source

All Articles