本文整理了Java中org.apache.log4j.helpers.Loader
类的一些代码示例,展示了Loader
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Loader
类的具体详情如下:
包路径:org.apache.log4j.helpers.Loader
类名称:Loader
[英]Load resources (or images) from various sources.
[中]从各种来源加载资源(或图像)。
代码示例来源:origin: log4j/log4j
/**
* Get a resource by delegating to getResource(String).
* @param resource resource name
* @param clazz class, ignored.
* @return URL to resource or null.
* @deprecated as of 1.2.
*/
public static URL getResource(String resource, Class clazz) {
return getResource(resource);
}
代码示例来源:origin: log4j/log4j
String className = subst(layout_element.getAttribute(CLASS_ATTR));
LogLog.debug("Parsing layout of class: \""+className+"\"");
try {
Object instance = Loader.loadClass(className).newInstance();
Layout layout = (Layout)instance;
PropertySetter propSetter = new PropertySetter(layout);
NodeList params = layout_element.getChildNodes();
final int length = params.getLength();
Node currentNode = (Node)params.item(loop);
if (currentNode.getNodeType() == Node.ELEMENT_NODE) {
Element currentElement = (Element) currentNode;
String tagName = currentElement.getTagName();
if(tagName.equals(PARAM_TAG)) {
setParameter(currentElement, propSetter);
} else {
parseUnrecognizedElement(instance, currentElement, props);
propSetter.activate();
return layout;
Thread.currentThread().interrupt();
LogLog.error("Could not create the Layout. Reported error follows.",
oops);
return null;
代码示例来源:origin: log4j/log4j
classLoader = getTCL();
if(classLoader != null) {
LogLog.debug("Trying to find ["+resource+"] using context classloader "
+classLoader+".");
url = classLoader.getResource(resource);
LogLog.debug("Trying to find ["+resource+"] using "+classLoader
+" class loader.");
url = classLoader.getResource(resource);
LogLog.warn(TSTR, t);
} catch(InvocationTargetException t) {
if (t.getTargetException() instanceof InterruptedException
代码示例来源:origin: log4j/log4j
String className = subst(appenderElement.getAttribute(CLASS_ATTR));
LogLog.debug("Class name: [" + className+']');
try {
Object instance = Loader.loadClass(className).newInstance();
Appender appender = (Appender)instance;
PropertySetter propSetter = new PropertySetter(appender);
appender.setName(subst(appenderElement.getAttribute(NAME_ATTR)));
NodeList children = appenderElement.getChildNodes();
final int length = children.getLength();
Node currentNode = children.item(loop);
if (currentNode.getNodeType() == Node.ELEMENT_NODE) {
Element currentElement = (Element)currentNode;
if (currentElement.getTagName().equals(PARAM_TAG)) {
setParameter(currentElement, propSetter);
propSetter.activate();
return appender;
代码示例来源:origin: org.ops4j.pax.logging/pax-logging-service
String className = subst(layout_element.getAttribute(CLASS_ATTR));
LogLog.debug("Parsing layout of class: \""+className+"\"");
try {
Object instance = Loader.loadClass(className).newInstance();
Layout layout = (Layout)instance;
PropertySetter propSetter = new PropertySetter(layout);
NodeList params = layout_element.getChildNodes();
final int length = params.getLength();
Node currentNode = (Node)params.item(loop);
if (currentNode.getNodeType() == Node.ELEMENT_NODE) {
Element currentElement = (Element) currentNode;
String tagName = currentElement.getTagName();
if(tagName.equals(PARAM_TAG)) {
setParameter(currentElement, propSetter);
propSetter.activate();
return layout;
LogLog.error("Could not create the Layout. Reported error follows.",
oops);
return null;
代码示例来源:origin: log4j/log4j
String priStr = subst(element.getAttribute(VALUE_ATTR));
LogLog.debug("Level value for "+catName+" is ["+priStr+"].");
LogLog.error("Root level cannot be inherited. Ignoring directive.");
} else {
logger.setLevel(null);
String className = subst(element.getAttribute(CLASS_ATTR));
if(EMPTY_STR.equals(className)) {
logger.setLevel(OptionConverter.toLevel(priStr, Level.DEBUG));
} else {
LogLog.debug("Desired Level sub-class: ["+className+']');
try {
Class clazz = Loader.loadClass(className);
Method toLevelMethod = clazz.getMethod("toLevel",
ONE_STRING_PARAM);
代码示例来源:origin: log4j/log4j
void parseCategory (Element loggerElement) {
String catName = subst(loggerElement.getAttribute(NAME_ATTR));
String className = subst(loggerElement.getAttribute(CLASS_ATTR));
LogLog.debug("Retreiving an instance of org.apache.log4j.Logger.");
cat = (catFactory == null) ? repository.getLogger(catName) : repository.getLogger(catName, catFactory);
LogLog.debug("Desired logger sub-class: ["+className+']');
try {
Class clazz = Loader.loadClass(className);
Method getInstanceMethod = clazz.getMethod("getLogger",
ONE_STRING_PARAM);
Thread.currentThread().interrupt();
LogLog.error("Could not retrieve category ["+catName+
"]. Reported error follows.", oops);
return;
boolean additivity = OptionConverter.toBoolean(
subst(loggerElement.getAttribute(ADDITIVITY_ATTR)),
true);
代码示例来源:origin: log4j/log4j
/**
Add a renderer to a hierarchy passed as parameter.
*/
static
public
void addRenderer(RendererSupport repository, String renderedClassName,
String renderingClassName) {
LogLog.debug("Rendering class: ["+renderingClassName+"], Rendered class: ["+
renderedClassName+"].");
ObjectRenderer renderer = (ObjectRenderer)
OptionConverter.instantiateByClassName(renderingClassName,
ObjectRenderer.class,
null);
if(renderer == null) {
LogLog.error("Could not instantiate renderer ["+renderingClassName+"].");
return;
} else {
try {
Class renderedClass = Loader.loadClass(renderedClassName);
repository.setRenderer(renderedClass, renderer);
} catch(ClassNotFoundException e) {
LogLog.error("Could not find class ["+renderedClassName+"].", e);
}
}
}
代码示例来源:origin: mrsarm/log4jwebtracker
String file = getInitParameter("log4jConfigLocation");
if (file==null) {
URL url = Loader.getResource("log4j.properties");
if(new File(url.getFile()).exists()) {
PropertyConfigurator.configure(url);
} else {
url = Loader.getResource("log4j.xml");
if(new File(url.getFile()).exists()) {
DOMConfigurator.configure(url);
} else {
System.err.println("*** Log4j configuration file not found. ***");
if(new File(path).exists()) {
if(path.indexOf(".xml")!=-1) {
DOMConfigurator.configure(path);
} else if(path.indexOf(".properties")!=-1) {
PropertyConfigurator.configure(path);
代码示例来源:origin: log4j/log4j
LogLog.error("Unrecognized format specifier [" + converterId + "]");
if (converterObj instanceof String) {
try {
converterClass = Loader.loadClass((String) converterObj);
} catch (ClassNotFoundException ex) {
LogLog.warn(
"Class for conversion pattern %" + converterName + " not found",
ex);
LogLog.warn(
"Bad map entry for conversion pattern %" + converterName + ".");
代码示例来源:origin: log4j/log4j
LogLog.debug("toLevel" + ":class=[" + clazz + "]"
+ ":pri=[" + levelName + "]");
Class customLevel = Loader.loadClass(clazz);
LogLog.warn("custom level class [" + clazz + "] not found.");
} catch(NoSuchMethodException e) {
LogLog.warn("custom level class [" + clazz + "]"
+ " does not have a class function toLevel(String, Level)", e);
} catch(java.lang.reflect.InvocationTargetException e) {
代码示例来源:origin: log4j/log4j
private
void readLevel(ObjectInputStream ois)
throws java.io.IOException, ClassNotFoundException {
int p = ois.readInt();
try {
String className = (String) ois.readObject();
if(className == null) {
level = Level.toLevel(p);
} else {
Method m = (Method) methodCache.get(className);
if(m == null) {
Class clazz = Loader.loadClass(className);
// Note that we use Class.getDeclaredMethod instead of
// Class.getMethod. This assumes that the Level subclass
// implements the toLevel(int) method which is a
// requirement. Actually, it does not make sense for Level
// subclasses NOT to implement this method. Also note that
// only Level can be subclassed and not Priority.
m = clazz.getDeclaredMethod(TO_LEVEL, TO_LEVEL_PARAMS);
methodCache.put(className, m);
}
PARAM_ARRAY[0] = new Integer(p);
level = (Level) m.invoke(null, PARAM_ARRAY);
}
} catch(Exception e) {
LogLog.warn("Level deserialization failed, reverting to default.", e);
level = Level.toLevel(p);
}
}
代码示例来源:origin: log4j/log4j
if(className != null) {
try {
Class classObj = Loader.loadClass(className);
if(!superClass.isAssignableFrom(classObj)) {
LogLog.error("A \""+className+"\" object is not assignable to a \""+
superClass.getName() + "\" variable.");
LogLog.error("The class \""+ superClass.getName()+"\" was loaded by ");
LogLog.error("["+superClass.getClassLoader()+"] whereas object of type ");
LogLog.error("\"" +classObj.getName()+"\" was loaded by ["
+classObj.getClassLoader()+"].");
代码示例来源:origin: log4j/log4j
/**
* If running under JDK 1.2 load the specified class using the
* <code>Thread</code> <code>contextClassLoader</code> if that
* fails try Class.forname. Under JDK 1.1 only Class.forName is
* used.
*
*/
static public Class loadClass (String clazz) throws ClassNotFoundException {
// Just call Class.forName(clazz) if we are running under JDK 1.1
// or if we are instructed to ignore the TCL.
if(java1 || ignoreTCL) {
return Class.forName(clazz);
} else {
try {
return getTCL().loadClass(clazz);
}
// we reached here because tcl was null or because of a
// security exception, or because clazz could not be loaded...
// In any case we now try one more time
catch(InvocationTargetException e) {
if (e.getTargetException() instanceof InterruptedException
|| e.getTargetException() instanceof InterruptedIOException) {
Thread.currentThread().interrupt();
}
} catch(Throwable t) {
}
}
return Class.forName(clazz);
}
}
代码示例来源:origin: log4j/log4j
private
MDC() {
java1 = Loader.isJava1();
if(!java1) {
tlm = new ThreadLocalMap();
}
try {
removeMethod = ThreadLocal.class.getMethod("remove", null);
} catch (NoSuchMethodException e) {
// don't do anything - java prior 1.5
}
}
代码示例来源:origin: camunda/camunda-bpm-platform
String className = subst(appenderElement.getAttribute(CLASS_ATTR));
LogLog.debug("Class name: [" + className+']');
try {
Object instance = Loader.loadClass(className).newInstance();
Appender appender = (Appender)instance;
PropertySetter propSetter = new PropertySetter(appender);
appender.setName(subst(appenderElement.getAttribute(NAME_ATTR)));
NodeList children = appenderElement.getChildNodes();
final int length = children.getLength();
Node currentNode = children.item(loop);
if (currentNode.getNodeType() == Node.ELEMENT_NODE) {
Element currentElement = (Element)currentNode;
if (currentElement.getTagName().equals(PARAM_TAG)) {
setParameter(currentElement, propSetter);
propSetter.activate();
return appender;
代码示例来源:origin: ops4j/org.ops4j.pax.logging
String className = subst(layout_element.getAttribute(CLASS_ATTR));
LogLog.debug("Parsing layout of class: \""+className+"\"");
try {
Object instance = Loader.loadClass(className).newInstance();
Layout layout = (Layout)instance;
PropertySetter propSetter = new PropertySetter(layout);
NodeList params = layout_element.getChildNodes();
final int length = params.getLength();
Node currentNode = (Node)params.item(loop);
if (currentNode.getNodeType() == Node.ELEMENT_NODE) {
Element currentElement = (Element) currentNode;
String tagName = currentElement.getTagName();
if(tagName.equals(PARAM_TAG)) {
setParameter(currentElement, propSetter);
propSetter.activate();
return layout;
LogLog.error("Could not create the Layout. Reported error follows.",
oops);
return null;
代码示例来源:origin: apache/log4j
String priStr = subst(element.getAttribute(VALUE_ATTR));
LogLog.debug("Level value for "+catName+" is ["+priStr+"].");
LogLog.error("Root level cannot be inherited. Ignoring directive.");
} else {
logger.setLevel(null);
String className = subst(element.getAttribute(CLASS_ATTR));
if(EMPTY_STR.equals(className)) {
logger.setLevel(OptionConverter.toLevel(priStr, Level.DEBUG));
} else {
LogLog.debug("Desired Level sub-class: ["+className+']');
try {
Class clazz = Loader.loadClass(className);
Method toLevelMethod = clazz.getMethod("toLevel",
ONE_STRING_PARAM);
代码示例来源:origin: camunda/camunda-bpm-platform
void parseCategory (Element loggerElement) {
String catName = subst(loggerElement.getAttribute(NAME_ATTR));
String className = subst(loggerElement.getAttribute(CLASS_ATTR));
LogLog.debug("Retreiving an instance of org.apache.log4j.Logger.");
cat = repository.getLogger(catName);
LogLog.debug("Desired logger sub-class: ["+className+']');
try {
Class clazz = Loader.loadClass(className);
Method getInstanceMethod = clazz.getMethod("getLogger",
ONE_STRING_PARAM);
cat = (Logger) getInstanceMethod.invoke(null, new Object[] {catName});
} catch (Exception oops) {
LogLog.error("Could not retrieve category ["+catName+
"]. Reported error follows.", oops);
return;
boolean additivity = OptionConverter.toBoolean(
subst(loggerElement.getAttribute(ADDITIVITY_ATTR)),
true);
代码示例来源:origin: camunda/camunda-bpm-platform
/**
Add a renderer to a hierarchy passed as parameter.
*/
static
public
void addRenderer(RendererSupport repository, String renderedClassName,
String renderingClassName) {
LogLog.debug("Rendering class: ["+renderingClassName+"], Rendered class: ["+
renderedClassName+"].");
ObjectRenderer renderer = (ObjectRenderer)
OptionConverter.instantiateByClassName(renderingClassName,
ObjectRenderer.class,
null);
if(renderer == null) {
LogLog.error("Could not instantiate renderer ["+renderingClassName+"].");
return;
} else {
try {
Class renderedClass = Loader.loadClass(renderedClassName);
repository.setRenderer(renderedClass, renderer);
} catch(ClassNotFoundException e) {
LogLog.error("Could not find class ["+renderedClassName+"].", e);
}
}
}
内容来源于网络,如有侵权,请联系作者删除!