我想禁用 struts2 验证的日志记录,每当调用包含验证的 struts 操作时,我的日志中都会出现“垃圾”,如下所示:
“[4 月 15 日 14:42:41] 错误 (CommonsLogger.java:24) - 域验证错误:blahblah。”。
我已经在使用 log4j 并且它的日志记录得很好,但我不想让这个“垃圾”填充我的日志。
如果需要一些代码,我会得到它,但此刻我不知道要呈现什么。
准确地说,这个“垃圾”日志正在记录 struts2 中的验证消息(例如“请输入您的姓名”),也许这会帮助别人帮助我。 :)
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. :)
发布评论
评论(2)
在 log4j 中,您可以修改每个类的日志记录级别,通常每个类都有自己的记录器。 但它们是分层的,因此您通常可以设置包的日志记录级别并影响其所有成员。 因此,将以下内容添加到您的
log4j.properties
文件中:不过,这是一个相当广泛的刷子——这样您就无法了解潜在的严重验证问题。 您可能想要查明哪个类正在发出日志记录消息并仅修改其日志记录。
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: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.
@milostrivun
log4j.logger.com.opensymphony.xwork2.validator = FATAL
这会将记录器级别设置为 FATAL,这相当于指示 log4j 记录优先级为 FATAL 或更高的消息(尽管没有比 FATAL 更高的级别)。
因此,来自 com.opensymphony.xwork2.validator 包中任何类的 TRACE、DEBUG、INFO、WARN、ERROR 级别的消息都不会被打印。
说得通?
@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?