我重新阅读了stackoverflow中的很多主题,但没有答案可以帮助我。
问题是什么:我有java代码:
Requirement req = response.getEntity(Requirement.class);
并且有警告:
WARNING: Property http://localhost/ttrDef-5 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)
at org.eclipse.lyo.oslc4j.provider.jena.JenaModelHelper.handleExtendedPropertyValue(JenaModelHelper.java:1079)
at org.eclipse.lyo.oslc4j.provider.jena.JenaModelHelper.fromResource(JenaModelHelper.java:584)
at org.eclipse.lyo.oslc4j.provider.jena.JenaModelHelper.createObjectResultList(JenaModelHelper.java:457)
at org.eclipse.lyo.oslc4j.provider.jena.JenaModelHelper.fromJenaModel(JenaModelHelper.java:395)
问题来自 JenaModelHelper 类中的警告
catch(DatatypeFormatException e)
{
/*1083*/ able(Level.WARNING))
/*1086*/ logger.log(Level.WARNING, (new StringBuilder()).append("Property ").append(propertyQName.getNamespaceURI()).append(propertyQName.getLocalPart()).append(" could not be parsed as datatype ").append(literal.getDatatypeURI()).toString(), e);
所以我想暂停这条消息,而不是所有其他消息,只有这个。所以我做了
Logger.getLogger(org.eclipse.lyo.oslc4j.provider.jena.JenaModelHelper.class).setLevel(Level.OFF);
Requirement req = response.getEntity(Requirement.class);
或
Logger.getLogger(org.eclipse.lyo.oslc4j.provider.jena.JenaModelHelper.class).setLevel(Level.FATAL);
Requirement req = response.getEntity(Requirement.class);
但是这个警告仍然没有发生在控制台中。我有这个代码循环并传递了100多次并有100个警告堆栈跟踪。这就产生了问题。
或
@SuppressWarnings("unchecked")
Requirement req = response.getEntity(Requirement.class);
我有 log4J.config.xml ,但我没有看到ConsoleAppender的任何内容。
如何仅针对此类JenaModelHelper或甚至包?提供警告?
答案 0 :(得分:0)
这将完美地完成你的工作:
final PrintStream err = new PrintStream(System.err);
System.setErr(new PrintStream("/dev/null"));
// ...
System.setErr(err); // dont forget to close it