views:

1604

answers:

3

I want to disable logging for struts2 validation,whenever a struts action called containing validation I get 'junk' in my log, smth like this : "[Apr 15 14:42:41] ERROR (CommonsLogger.java:24) - Validation error for domain:blahblah.".

I'm already using log4j and it's logging just fine but I don't want to this 'junk' filling my log.

If some code is nedded I will get it but at this moment I don't know what to present.

To be precise this 'junk' logs are logging the validation messages in struts2 (e.g 'Please enter your name'),maybe this will help someone help me. :)

A: 

In log4j you can modify the logging level per-class, and typically every class has its own logger. But they're hierarchical, so you can typically set the logging level for a package and affect all its members. So add the following to your log4j.properties file:

log4j.logger.com.opensymphony.xwork2.validator = FATAL

This is a pretty broad brush though -- with this you won't get visibility into potentially serious problems with validation. You may want to pinpoint which class is emitting the logging message and only modify its logging.

Chris Winters
this seems to be the solution but I can't get it what is exactly to put to FATAL logging
If you change your log4j ConversionPattern to include the package + class you'll be able to pinpoint where it's coming from. See the javadocs for PatternLayout to figure out how to put both in. (It's verbose, so you can revert back to your old pattern once you figure out what's emitting those messages.)
Chris Winters
A: 

Kind of really weird.

log4j.properties: log4j.logger.com.opensymphony.xwork2.util.logging.commons.CommonsLogger=FATAL

log file: "ERROR (CommonsLogger.java:24:com.opensymphony.xwork2.util.logging.commons.CommonsLogger) - Validation error for..."

Any idea?

A: 

@milostrivun

log4j.logger.com.opensymphony.xwork2.validator = FATAL

This would set the logger level to FATAL which is equivalent to instructing log4j to log message which are of priority FATAL or more(Though there is no higher level than FATAL).

So, the TRACE, DEBUG, INFO, WARN, ERROR level messages coming from any class within the com.opensymphony.xwork2.validator packagae would not get printed.

Makes sense?

Mohd Farid