当前位置: 首页>>代码示例>>Java>>正文


Java Loader类代码示例

本文整理汇总了Java中org.apache.log4j.helpers.Loader的典型用法代码示例。如果您正苦于以下问题:Java Loader类的具体用法?Java Loader怎么用?Java Loader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Loader类属于org.apache.log4j.helpers包,在下文中一共展示了Loader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addRenderer

import org.apache.log4j.helpers.Loader; //导入依赖的package包/类
/**
    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);
     }
   }
 }
 
开发者ID:DiamondLightSource,项目名称:daq-eclipse,代码行数:26,代码来源:RendererMap.java

示例2: initLogging

import org.apache.log4j.helpers.Loader; //导入依赖的package包/类
/**
 * @param configLocation location.
 */
protected void initLogging(final String configLocation) {
    log("initLogging [" + configLocation + "].");
    URL url = null;
    try {
        url = new URL(configLocation);
        log("found url: " + url);
    } catch (@SuppressWarnings("unused") final MalformedURLException ex) {
        // so, resource is not a URL:
        // attempt to get the resource from the class path
        log("attempt to get the resource from the class path.");
        url = Loader.getResource(configLocation);
    }
    if (url != null) {
        log("Using URL [" + url + "] for automatic log4j configuration.");

        if (configLocation.toLowerCase(Locale.ENGLISH).endsWith(".xml")) {
            DOMConfigurator.configure(url);
        } else {
            PropertyConfigurator.configure(url);
        }

    } else {
        log("Could not find resource: [" + configLocation + "].");
    }
}
 
开发者ID:brabenetz,项目名称:settings4j,代码行数:29,代码来源:Log4jConfigurationLoader.java

示例3: readLevel

import org.apache.log4j.helpers.Loader; //导入依赖的package包/类
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);
   }
 }
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:31,代码来源:LoggingEvent.java

示例4: MDC

import org.apache.log4j.helpers.Loader; //导入依赖的package包/类
private
MDC() {
  java1 = Loader.isJava1();
  if(!java1) {
    tlm = new ThreadLocalMap();
  }
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:8,代码来源:MDC.java

示例5: parseLayout

import org.apache.log4j.helpers.Loader; //导入依赖的package包/类
/**
    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;
   }
 }
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:38,代码来源:DOMConfigurator.java

示例6: parseLevel

import org.apache.log4j.helpers.Loader; //导入依赖的package包/类
/**
    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());    
 }
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:42,代码来源:DOMConfigurator.java

示例7: MDC

import org.apache.log4j.helpers.Loader; //导入依赖的package包/类
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
  }
}
 
开发者ID:DiamondLightSource,项目名称:daq-eclipse,代码行数:14,代码来源:MDC.java

示例8: parseLayout

import org.apache.log4j.helpers.Loader; //导入依赖的package包/类
/**
    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) {
       if (oops instanceof InterruptedException || oops instanceof InterruptedIOException) {
           Thread.currentThread().interrupt();
       }
     LogLog.error("Could not create the Layout. Reported error follows.",
	   oops);
     return null;
   }
 }
 
开发者ID:DiamondLightSource,项目名称:daq-eclipse,代码行数:41,代码来源:DOMConfigurator.java

示例9: parseThrowableRenderer

import org.apache.log4j.helpers.Loader; //导入依赖的package包/类
/**
 * Parses throwable renderer.
 * @param element throwableRenderer element.
 * @return configured throwable renderer.
 * @since 1.2.16.
 */
protected ThrowableRenderer parseThrowableRenderer(final Element element) {
    String className = subst(element.getAttribute(CLASS_ATTR));
    LogLog.debug("Parsing throwableRenderer of class: \""+className+"\"");
    try {
      Object instance 	= Loader.loadClass(className).newInstance();
      ThrowableRenderer tr   	= (ThrowableRenderer)instance;
      PropertySetter propSetter = new PropertySetter(tr);

      NodeList params 	= 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 tr;
    }
    catch (Exception oops) {
        if (oops instanceof InterruptedException || oops instanceof InterruptedIOException) {
            Thread.currentThread().interrupt();
        }
        LogLog.error("Could not create the ThrowableRenderer. Reported error follows.",
           oops);
      return null;
    }
}
 
开发者ID:DiamondLightSource,项目名称:daq-eclipse,代码行数:43,代码来源:DOMConfigurator.java

示例10: reset

import org.apache.log4j.helpers.Loader; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private static void reset() throws MalformedURLException {
  for (Enumeration<Logger> logger = LogManager.getCurrentLoggers(); logger.hasMoreElements(); ) {
    logger.nextElement().setLevel(null);
  }

  String path = System.getProperty(JAVA_OPTIONS_LOG_CONFIG);
  if (Strings.isNullOrEmpty(path)) {
    PropertyConfigurator.configure(Loader.getResource(LOG_CONFIGURATION));
  } else {
    PropertyConfigurator.configure(new URL(path));
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:14,代码来源:SetLoggingLevelCommand.java

示例11: setUp

import org.apache.log4j.helpers.Loader; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    TestUtils.reconfigureSettings4jWithDefaultConfig();

    // clearProperties
    System.clearProperty(LOG4J_CONFIG_KEY);
    System.clearProperty(LOG4J_DOCUMENT_BUILDER_FACTORY);

    // Configure Log4j
    DOMConfigurator.configure(Loader.getResource("org/settings4j/helper/web/log4j-Config-Default.xml"));
}
 
开发者ID:brabenetz,项目名称:settings4j,代码行数:12,代码来源:Log4jConfigurationLoaderTest.java

示例12: tearDown

import org.apache.log4j.helpers.Loader; //导入依赖的package包/类
@After
public void tearDown() throws Exception {
    System.clearProperty(LOG4J_CONFIG_KEY);
    System.clearProperty(LOG4J_DOCUMENT_BUILDER_FACTORY);
    DOMConfigurator.configure(Loader.getResource("log4j.xml"));
    InMemoryLog4jAppender.linesClear();
}
 
开发者ID:brabenetz,项目名称:settings4j,代码行数:8,代码来源:Log4jConfigurationLoaderTest.java

示例13: main

import org.apache.log4j.helpers.Loader; //导入依赖的package包/类
public static void main( final String[] args ) throws InterruptedException
{
    // Initialize log4j
    PropertyConfigurator.configure( Loader.getResource( "log4j.properties" ) );

    // Initialize Spring
    final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    context.scan( "com.hood.transcoder.spring" );
    context.refresh();

    // Run application
    final TranscoderApplication transcoderApplication =
            (TranscoderApplication) context.getBean( "transcoderApplication" );
    final TranscodeNotificationListener transcodeNotificationListener =
            (TranscodeNotificationListener) context.getBean( "transcodeNotificationListener" );
    final Thread transcodeNotificationListenerThread =
            new Thread( transcodeNotificationListener, "TranscodeNotificationListener" );
    transcodeNotificationListenerThread.start();

    if ( args != null )
    {
        for ( final String arg : args )
        {
            final Path path = FileSystems.getDefault().getPath( arg );
            transcoderApplication.transcodePath( path );
        }
    }

    while ( transcoderApplication.hasOutstandingJobs() )
    {
        Thread.sleep( TimeUnit.SECONDS.toMillis( 1 ) );
    }

    context.close();
}
 
开发者ID:stevenmhood,项目名称:transcoder,代码行数:36,代码来源:Launcher.java

示例14: readLevel

import org.apache.log4j.helpers.Loader; //导入依赖的package包/类
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);
  }
}
 
开发者ID:OurGrid,项目名称:commune,代码行数:31,代码来源:LoggingEvent.java

示例15: parseAppender

import org.apache.log4j.helpers.Loader; //导入依赖的package包/类
/**
    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;
   }
 }
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:68,代码来源:DOMConfigurator.java


注:本文中的org.apache.log4j.helpers.Loader类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。