4

I'd like to disable the portion of log4j that logs all class/method paths that are being 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 would like 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 haven't configured a log4j properties file. I want to keep INFO being sent to stdout as it is, but just avoid these method calls logs.

update

I've since created a log4j.properties file, but I can't find any settings to disable the logging of method calls.

NOTE; I'm not trying to change the "format" of log messages, but disable the logging of method calls altogether.

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
Ben
  • 60,438
  • 111
  • 314
  • 488
  • How do you set up your appender? If you don't use a properties file, please show the configuration code. – Simulant Apr 17 '13 at 20:44
  • What is logging level for Apr 15, 2013 10:50:52 AM com.production.tasks.ImportNewOrders checkForOrders entry? INFO? DEBUG? – Piotr Kochański Apr 17 '13 at 21:07
  • @PiotrKochański That's exactly the line I'm trying to get rid of. It appears to not be affected by the logging level. – Ben Apr 18 '13 at 00:40
  • What application server are you using? – higuaro Apr 21 '13 at 03:14
  • "Currently I haven't configured a log4j properties file." Why not? Care to define one? Then you can easily adapt the log format... – skirsch Apr 25 '13 at 07:23
  • @skirsch - I've since created a log4j.properties, but it still does not affect the logging of the method calls as shown above. – Ben Apr 25 '13 at 16:58

3 Answers3

2

Those are not log4j calls. What you're seeing is the default java.util.logging pattern (to stderr). So you need to configure java.util.logging appropriately. See http://tutorials.jenkov.com/java-logging/configuration.html

artbristol
  • 32,010
  • 5
  • 70
  • 103
1

If you are using a PatternLayout to configure your Appender, you should remove the %l that outputs the calling method with the fully quallified name. Your Layout should be look something like this:

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

But I recommend to put in some kind of a time stamp with something of this:

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

Simulant
  • 19,190
  • 8
  • 63
  • 98
1

If you do not have a log4j properties file setup externally then some component in your app is programmatically configuring it. In any case, you need to override whatever current configuration you have now with what you really want. The easiest and most manageable way to do this would be to create a valid properties file and place it in your class path. Doing so will allow you to not only override the configuration of existing loggers, but also to define new ones.

If needed, you can also programmatically modify your Log4J configuration. Easiest accomplished via a static initializer in startup class. 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());
    }
}
Perception
  • 79,279
  • 19
  • 185
  • 195