在运行时更改外部类日志记录级别后如何刷新log4j [英] How to refresh log4j after change of the external class logging level at runtime

查看:87
本文介绍了在运行时更改外部类日志记录级别后如何刷新log4j的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些要禁用的警告.它们来自

org.eclipse.lyo.oslc4j.provider.jena.JenaModelHelper

班.所以我正在使用log4j,我在rutime打电话

Logger.getLogger("org.eclipse.lyo.oslc4j.provider.jena.JenaModelHelper").setLevel(Level.OFF);

但是什么也没发生.

为此目的,我调试了有问题的代码,并在前3次显示警告,但在第4个命中级别已更改. 我在begging(在构造函数中)处更改了日志级别,因此当考虑到运行时应用规则时,我想在log4j中有一些刷新机制.

有没有一种方法可以立即触发这种情况?

警告消息是:

WARNING: Property http://localhost:8080/dwa/rm/urn:rational::1-55422447386d3378-M-00000200/types/attrDef-7 could not be parsed as datatype http://www.w3.org/2001/XMLSchema#dateTime
com.hp.hpl.jena.datatypes.DatatypeFormatException: Lexical form '2015-06-10' is not a legal instance of Datatype[http://www.w3.org/2001/XMLSchema#dateTime -> class com.hp.hpl.jena.datatypes.xsd.XSDDateTime] Lexical form '2015-06-10' is not a legal instance of Datatype[http://www.w3.org/2001/XMLSchema#dateTime -> class com.hp.hpl.jena.datatypes.xsd.XSDDateTime] during parse -org.apache.xerces.impl.dv.InvalidDatatypeValueException: cvc-datatype-valid.1.2.1: '2015-06-10' is not a valid value for 'dateTime'.
    at com.hp.hpl.jena.graph.impl.LiteralLabelImpl.getValue(LiteralLabelImpl.java:339)
    at com.hp.hpl.jena.graph.Node_Literal.getLiteralValue(Node_Literal.java:39)
    at com.hp.hpl.jena.rdf.model.impl.LiteralImpl.getValue(LiteralImpl.java:98)

解决方案

您可以禁用登录配置文件(log4j.properties),因此将在启动时进行设置:

log4j.logger.org.eclipse.lyo.oslc4j.provider.jena.JenaModelHelper = ERROR

您发布的警告看起来很像Java Util Logging消息,由于Log4J是一个不同的框架,因此不会被Log4J控制.您可以在VM的"logging.properties"文件中禁用该消息:

org.eclipse.lyo.oslc4j.provider.jena.JenaModelHelper.level=SEVERE

或者您可以将 SLF4J 添加到您的项目中,以将旧框架消息重定向到Log4J.为此,请 slf4j-api.jar

but nothing happens.

For that purpose I debug the problematic code and first 3 times the warn was displayed, but on the 4-th hit the level was changed. I changed the log level at the begging(in the constructor) so I suppose there is some refresh mechanism in the log4j when the runtime applied rule is take into account.

Is there a way to trigger this to happen immediately?

Edit: The warning message is:

WARNING: Property http://localhost:8080/dwa/rm/urn:rational::1-55422447386d3378-M-00000200/types/attrDef-7 could not be parsed as datatype http://www.w3.org/2001/XMLSchema#dateTime
com.hp.hpl.jena.datatypes.DatatypeFormatException: Lexical form '2015-06-10' is not a legal instance of Datatype[http://www.w3.org/2001/XMLSchema#dateTime -> class com.hp.hpl.jena.datatypes.xsd.XSDDateTime] Lexical form '2015-06-10' is not a legal instance of Datatype[http://www.w3.org/2001/XMLSchema#dateTime -> class com.hp.hpl.jena.datatypes.xsd.XSDDateTime] during parse -org.apache.xerces.impl.dv.InvalidDatatypeValueException: cvc-datatype-valid.1.2.1: '2015-06-10' is not a valid value for 'dateTime'.
    at com.hp.hpl.jena.graph.impl.LiteralLabelImpl.getValue(LiteralLabelImpl.java:339)
    at com.hp.hpl.jena.graph.Node_Literal.getLiteralValue(Node_Literal.java:39)
    at com.hp.hpl.jena.rdf.model.impl.LiteralImpl.getValue(LiteralImpl.java:98)

解决方案

You can disable the logging in you configuration file (log4j.properties), so this will be set at startup already:

log4j.logger.org.eclipse.lyo.oslc4j.provider.jena.JenaModelHelper=ERROR

The warning you posted looks much like a Java Util Logging message, those wont be controled by Log4J because its a different framework. You can either disable the message in your VMs "logging.properties" file:

org.eclipse.lyo.oslc4j.provider.jena.JenaModelHelper.level=SEVERE

Or you can add SLF4J to your project to redirect legacy framework messages to Log4J. To do this put slf4j-api.jar, jcl-over-slf4j.jar, jul-to-slf4j.jar and slf4j-log4j12.jar in your classpath.

这篇关于在运行时更改外部类日志记录级别后如何刷新log4j的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆