org.apache.log4j.helpers.Loader Java Examples
The following examples show how to use
org.apache.log4j.helpers.Loader.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RendererMap.java From cacheonix-core with GNU Lesser General Public License v2.1 | 6 votes |
/** 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); } } }
Example #2
Source File: URLUtil.java From boubei-tss with Apache License 2.0 | 5 votes |
/** * 获取资源文件的绝对路径 * * @param file * @return */ public static URL getResourceFileUrl(String file) { if(file == null) return null; URL url = Loader.getResource(file); if (url == null) { url = ClassLoader.class.getResource(file); } return url; }
Example #3
Source File: LoggingEvent.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
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); } }
Example #4
Source File: MDC.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
private MDC() { java1 = Loader.isJava1(); if(!java1) { tlm = new ThreadLocalMap(); } }
Example #5
Source File: DOMConfigurator.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
/** Used internally to parse a layout element. */ protected Layout parseLayout (Element layout_element) { 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(); for (int loop = 0; loop < length; loop++) { 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; } catch (Exception oops) { LogLog.error("Could not create the Layout. Reported error follows.", oops); return null; } }
Example #6
Source File: DOMConfigurator.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
/** Used internally to parse a level element. */ protected void parseLevel(Element element, Logger logger, boolean isRoot) { String catName = logger.getName(); if(isRoot) { catName = "root"; } String priStr = subst(element.getAttribute(VALUE_ATTR)); LogLog.debug("Level value for "+catName+" is ["+priStr+"]."); if(INHERITED.equalsIgnoreCase(priStr) || NULL.equalsIgnoreCase(priStr)) { if(isRoot) { LogLog.error("Root level cannot be inherited. Ignoring directive."); } else { logger.setLevel(null); } } else { 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); Level pri = (Level) toLevelMethod.invoke(null, new Object[] {priStr}); logger.setLevel(pri); } catch (Exception oops) { LogLog.error("Could not create level ["+priStr+ "]. Reported error follows.", oops); return; } } } LogLog.debug(catName + " level set to " + logger.getLevel()); }
Example #7
Source File: DOMConfigurator.java From cacheonix-core with GNU Lesser General Public License v2.1 | 4 votes |
/** Used internally to parse an appender element. */ protected Appender parseAppender (Element appenderElement) { 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(); for (int loop = 0; loop < length; loop++) { Node currentNode = children.item(loop); /* We're only interested in Elements */ if (currentNode.getNodeType() == Node.ELEMENT_NODE) { Element currentElement = (Element)currentNode; // Parse appender parameters if (currentElement.getTagName().equals(PARAM_TAG)) { setParameter(currentElement, propSetter); } // Set appender layout else if (currentElement.getTagName().equals(LAYOUT_TAG)) { appender.setLayout(parseLayout(currentElement)); } // Add filters else if (currentElement.getTagName().equals(FILTER_TAG)) { parseFilters(currentElement, appender); } else if (currentElement.getTagName().equals(ERROR_HANDLER_TAG)) { parseErrorHandler(currentElement, appender); } else if (currentElement.getTagName().equals(APPENDER_REF_TAG)) { String refName = subst(currentElement.getAttribute(REF_ATTR)); if(appender instanceof AppenderAttachable) { AppenderAttachable aa = (AppenderAttachable) appender; LogLog.debug("Attaching appender named ["+ refName+ "] to appender named ["+ appender.getName()+"]."); aa.addAppender(findAppenderByReference(currentElement)); } else { LogLog.error("Requesting attachment of appender named ["+ refName+ "] to appender named ["+ appender.getName()+ "] which does not implement org.apache.log4j.spi.AppenderAttachable."); } } else { parseUnrecognizedElement(instance, currentElement, props); } } } propSetter.activate(); return appender; } /* Yes, it's ugly. But all of these exceptions point to the same problem: we can't create an Appender */ catch (Exception oops) { LogLog.error("Could not create an Appender. Reported error follows.", oops); return null; } }