How to refresh log4j after change of the external

2019-07-13 19:40发布

问题:

I have some warnings which I want to disable. They comes from the

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

class. So I am using log4j and I call at rutime

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

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)

回答1:

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.