org.apache.log4j.Appender.setLayout()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(7.7k)|赞(0)|评价(0)|浏览(190)

本文整理了Java中org.apache.log4j.Appender.setLayout()方法的一些代码示例,展示了Appender.setLayout()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Appender.setLayout()方法的具体详情如下:
包路径:org.apache.log4j.Appender
类名称:Appender
方法名:setLayout

Appender.setLayout介绍

[英]Set the Layout for this appender.
[中]设置此追加器的布局。

代码示例

代码示例来源:origin: pentaho/pentaho-kettle

public static void setLayout( Layout layout ) {
 LogWriter.layout = layout; // save for later creation of new files...
 Enumeration<?> appenders = logWriter.pentahoLogger.getAllAppenders();
 while ( appenders.hasMoreElements() ) {
  Appender appender = (Appender) appenders.nextElement();
  if ( appender instanceof Log4jConsoleAppender || appender instanceof Log4jFileAppender ) {
   appender.setLayout( layout );
  }
 }
}

代码示例来源:origin: log4j/log4j

public
Object invoke(String operationName, Object params[], String signature[])
 throws MBeanException,
 ReflectionException {
 if(operationName.equals("activateOptions") &&
          appender instanceof OptionHandler) {
  OptionHandler oh = (OptionHandler) appender;
  oh.activateOptions();
  return "Options activated.";
 } else if (operationName.equals("setLayout")) {
  Layout layout = (Layout) OptionConverter.instantiateByClassName((String)
                  params[0],
                  Layout.class,
                  null);
  appender.setLayout(layout);
  registerLayoutMBean(layout);
 }
 return null;
}

代码示例来源:origin: log4j/log4j

appender.setLayout(parseLayout(currentElement));

代码示例来源:origin: log4j/log4j

null);
if(layout != null) {
 appender.setLayout(layout);
 LogLog.debug("Parsing layout options for \"" + appenderName +"\".");

代码示例来源:origin: cloudfoundry/uaa

@Test
public void logged_exceptions_are_formatted_per_line_when_treating_throwable_as_lines() throws Exception {
  ByteArrayOutputStream output = new ByteArrayOutputStream();
  LineAwareLayout lineAwareLayout = new LineAwareLayout();
  lineAwareLayout.setLineLayout(new PatternLayout("%m" + delimiter));
  Appender appender = new WriterAppender(lineAwareLayout, output);
  appender.setName("TestLog");
  appender.setLayout(lineAwareLayout);
  Logger testLogger = LogManager.getLogger("test-logger");
  testLogger.addAppender(appender);
  testLogger.setLevel(Level.INFO);
  Exception ex = new Exception("SOMETHING BAD HAPPEN\nNO REALLY IT'S VERY BAD\n\ntrust me");
  ex.setStackTrace(new StackTraceElement[]{new StackTraceElement("CLAZZ", "MEETOD", "FEEL", 123)});
  testLogger.info(ex, ex);
  String expectedLog = String.join(delimiter, ex.toString().split("\n")) + delimiter + "\tat CLAZZ.MEETOD(FEEL:123)" + delimiter;
  assertEquals(expectedLog, output.toString());
}

代码示例来源:origin: cloudfoundry/uaa

@Test
public void messages_over_multiple_lines_are_formatted_per_line() throws Exception {
  ByteArrayOutputStream output = new ByteArrayOutputStream();
  LineAwareLayout lineAwareLayout = new LineAwareLayout();
  lineAwareLayout.setLineLayout(new PatternLayout("%m" + delimiter));
  Appender appender = new WriterAppender(lineAwareLayout, output);
  appender.setName("TestLog");
  appender.setLayout(lineAwareLayout);
  Logger testLogger = LogManager.getLogger("test-logger");
  testLogger.addAppender((appender));
  testLogger.setLevel(Level.INFO);
  String eventMessage = "test message\nwith\nmultiple lines";
  testLogger.info(eventMessage);
  String expectedLog = String.join(delimiter, eventMessage.split("\n")) + delimiter;
  assertEquals(expectedLog, output.toString());
}

代码示例来源:origin: cloudfoundry/uaa

@Test
public void messages_get_the_message_format_applied_after_the_line_format() throws Exception {
  ByteArrayOutputStream output = new ByteArrayOutputStream();
  String extraLine = "\nTHESE NEWLINES SHOULD NOT GET AFFECTED BY THE LINE FORMAT\n";
  LineAwareLayout lineAwareLayout = new LineAwareLayout();
  lineAwareLayout.setLineLayout(new PatternLayout("%m" + delimiter));
  lineAwareLayout.setMessageLayout(new PatternLayout("%m" + extraLine));
  Appender appender = new WriterAppender(lineAwareLayout, output);
  appender.setName("TestLog");
  appender.setLayout(lineAwareLayout);
  Logger testLogger = LogManager.getLogger("test-logger");
  testLogger.addAppender((appender));
  testLogger.setLevel(Level.INFO);
  String eventMessage = "test message\nwith\nmultiple lines";
  testLogger.info(eventMessage);
  String expectedLog = String.join(delimiter, eventMessage.split("\n")) + delimiter
    + extraLine;
  assertEquals(expectedLog, output.toString());
}

代码示例来源:origin: apache/log4j

public
Object invoke(String operationName, Object params[], String signature[])
 throws MBeanException,
 ReflectionException {
 if(operationName.equals("activateOptions") &&
          appender instanceof OptionHandler) {
  OptionHandler oh = (OptionHandler) appender;
  oh.activateOptions();
  return "Options activated.";
 } else if (operationName.equals("setLayout")) {
  Layout layout = (Layout) OptionConverter.instantiateByClassName((String)
                  params[0],
                  Layout.class,
                  null);
  appender.setLayout(layout);
  registerLayoutMBean(layout);
 }
 return null;
}

代码示例来源:origin: camunda/camunda-bpm-platform

appender.setLayout(parseLayout(currentElement));

代码示例来源:origin: apache/log4j

appender.setLayout(parseLayout(currentElement));

代码示例来源:origin: apache/log4j

null);
if(layout != null) {
 appender.setLayout(layout);
 LogLog.debug("Parsing layout options for \"" + appenderName +"\".");

代码示例来源:origin: matsim-org/matsim

/**
   * Appends a line break to the logger pattern (default behavior).
   */
  public static void enableNewLine() {
    Appender appender = Logger.getRootLogger().getAppender("stdout");
    appender.setLayout(defaultLayout);
  }
}

代码示例来源:origin: org.terracotta/terracotta-l1-ee

@Override
public void setLayout(Layout arg0) {
 delegate().setLayout(arg0);
}

代码示例来源:origin: org.jboss.as/jboss-as-logging

/**
 * Construct a new instance, possibly applying a {@code Layout} to the given appender instance.
 *
 * @param appender    the appender to delegate to
 * @param applyLayout {@code true} to apply an emulated layout, {@code false} otherwise
 */
public Log4jAppenderHandler(final Appender appender, final boolean applyLayout) {
  this.applyLayout = applyLayout;
  if (applyLayout) {
    appender.setLayout(null);
  }
  appenderUpdater.set(this, appender);
}

代码示例来源:origin: camunda/camunda-bpm-platform

null);
if(layout != null) {
 appender.setLayout(layout);
 LogLog.debug("Parsing layout options for \"" + appenderName +"\".");

代码示例来源:origin: cagataygurturk/lambadaframework

private static Appender getAppender() {
  if (appender == null) {
    PatternLayout patternLayout = new PatternLayout();
    patternLayout.setConversionPattern("%d{yyyy-MM-dd HH:mm:ss} <%X{AWSRequestId}> %-5p %c{1}:%L - %m%n");
    appender = new LambdaAppender();
    appender.setLayout(patternLayout);
  }
  return appender;
}

代码示例来源:origin: matsim-org/matsim

/**
 * Remove the line break form the logger pattern. Subsequent writes to stdout are printed to the same line.
 */
public static void disableNewLine() {
  Appender appender = Logger.getRootLogger().getAppender("stdout");
  defaultLayout = (PatternLayout)appender.getLayout();
  PatternLayout newLayout = new PatternLayout(defaultLayout.getConversionPattern().replace("%n",""));
  appender.setLayout(newLayout);
}

代码示例来源:origin: org.wildfly.core/wildfly-logging

@Override
public void setFormatter(final Formatter newFormatter) throws SecurityException {
  if (applyLayout) {
    final Appender appender = this.appender;
    if (appender != null) {
      appender.setLayout(new FormatterLayout(newFormatter));
    }
  }
  super.setFormatter(newFormatter);
}

代码示例来源:origin: wildfly/wildfly-core

@Override
public void setFormatter(final Formatter newFormatter) throws SecurityException {
  if (applyLayout) {
    final Appender appender = this.appender;
    if (appender != null) {
      appender.setLayout(new FormatterLayout(newFormatter));
    }
  }
  super.setFormatter(newFormatter);
}

代码示例来源:origin: waterguo/antsdb

public BetterCommandLine() {
  BasicConfigurator.configure();
  LogManager.getRootLogger().setLevel(Level.OFF);
  Appender appender = (Appender)LogManager.getRootLogger().getAllAppenders().nextElement();
  appender.setLayout(new PatternLayout("%d{HH:mm:ss,SSS} [%t] %-5p %c{2} - %m%n"));
}

相关文章