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


Java Appender.setLayout方法代码示例

本文整理汇总了Java中org.apache.log4j.Appender.setLayout方法的典型用法代码示例。如果您正苦于以下问题:Java Appender.setLayout方法的具体用法?Java Appender.setLayout怎么用?Java Appender.setLayout使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.log4j.Appender的用法示例。


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

示例1: init

import org.apache.log4j.Appender; //导入方法依赖的package包/类
public static void init(Level level)
{
	if (!alreadyInitialized)
	{
		synchronized(Log4jInit.class)
		{
			if (!alreadyInitialized)
			{
				BasicConfigurator.configure();
				Logger.getRootLogger().setLevel(level);

				Enumeration<?> enumAppenders = Logger.getRootLogger().getAllAppenders();
				while (enumAppenders.hasMoreElements())
				{
					Appender appender = (Appender) enumAppenders.nextElement();
					appender.setLayout(new VerySimpleLayout());
				}

				alreadyInitialized = true;
			}
		}
	}

}
 
开发者ID:digitalheir,项目名称:java-rechtspraak-library,代码行数:25,代码来源:Log4jInit.java

示例2: configureLogging

import org.apache.log4j.Appender; //导入方法依赖的package包/类
public static void configureLogging() {
    String fileName = MultiValueConfigLoader.getConfig("LOGGER-file");
    String maxFileSize = MultiValueConfigLoader.getConfig("LOGGER-maxLogSize", "10MB");
    int maxBackups = Integer.parseInt(MultiValueConfigLoader.getConfig("LOGGER-maxBackups", "5"));
    String logLevel = MultiValueConfigLoader.getConfig("LOGGER-level", "DEBUG");
    String logPattern = MultiValueConfigLoader.getConfig("LOGGER-logPattern", DEFAULT_PATTERN);

    Appender stdoutAppender = Logger.getRootLogger().getAppender("stdout");
    if (stdoutAppender != null) {
        PatternLayout layout = new PatternLayout();
        layout.setConversionPattern(logPattern);
        stdoutAppender.setLayout(layout);
    }
    setupTextFileLogger(fileName, maxFileSize, maxBackups, logLevel, logPattern);
}
 
开发者ID:RapturePlatform,项目名称:Rapture,代码行数:16,代码来源:LogManager.java

示例3: configureStdoutLayout

import org.apache.log4j.Appender; //导入方法依赖的package包/类
/**
 * Shell output doesn't need to be fancy, just the message and a line break
 */
private void configureStdoutLayout() {
    Appender stdoutAppender = Logger.getRootLogger().getAppender("stdout");
    PatternLayout p = new PatternLayout();
    p.setConversionPattern("%m%n");
    stdoutAppender.setLayout(p);
}
 
开发者ID:RapturePlatform,项目名称:Rapture,代码行数:10,代码来源:PluginShell.java

示例4: getLogger

import org.apache.log4j.Appender; //导入方法依赖的package包/类
public static Logger getLogger(final Class<?> cls) {
    boolean rootIsConfigured = Logger.getRootLogger().getAllAppenders().hasMoreElements();
    if (!rootIsConfigured) {
        BasicConfigurator.configure();
        Logger.getRootLogger().setLevel(Level.INFO);

        Appender appender = (Appender) Logger.getRootLogger().getAllAppenders().nextElement();
        appender.setLayout(new PatternLayout(" %-5p %d [%t] %C{1}: %m%n"));
    }

    return Logger.getLogger(cls);
}
 
开发者ID:tarun3kumar,项目名称:seleniumtestsframework,代码行数:13,代码来源:TestLogging.java

示例5: parseAppender

import org.apache.log4j.Appender; //导入方法依赖的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

示例6: parseAppender

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


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