當前位置: 首頁>>代碼示例>>Java>>正文


Java PatternLayout類代碼示例

本文整理匯總了Java中ch.qos.logback.classic.PatternLayout的典型用法代碼示例。如果您正苦於以下問題:Java PatternLayout類的具體用法?Java PatternLayout怎麽用?Java PatternLayout使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


PatternLayout類屬於ch.qos.logback.classic包,在下文中一共展示了PatternLayout類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: configure

import ch.qos.logback.classic.PatternLayout; //導入依賴的package包/類
@Override
public void configure(LoggerContext lc) {
  addInfo("Setting up robot logging configuration.");

  ConsoleAppender<ILoggingEvent> ca = new ConsoleAppender<>();
  ca.setContext(lc);
  ca.setName("console");
  LayoutWrappingEncoder<ILoggingEvent> encoder = new LayoutWrappingEncoder<>();
  encoder.setContext(lc);

  PatternLayout layout = new PatternLayout();
  layout.setPattern("%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n");

  layout.setContext(lc);
  layout.start();
  encoder.setLayout(layout);

  ca.setEncoder(encoder);
  ca.start();

  Logger rootLogger = lc.getLogger(Logger.ROOT_LOGGER_NAME);
  rootLogger.addAppender(ca);
  rootLogger.setLevel(Level.DEBUG);
}
 
開發者ID:strykeforce,項目名稱:thirdcoast,代碼行數:25,代碼來源:LoggingConfigurator.java

示例2: enablePaperTrail

import ch.qos.logback.classic.PatternLayout; //導入依賴的package包/類
private static void enablePaperTrail(final String hostname, final int port, final String ident) {
    final LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();

    final PatternLayout patternLayout = new PatternLayout();
    patternLayout.setContext(lc);
    patternLayout.setPattern(LOG_PATTERN);
    patternLayout.start();

    final SSLTCPNetSyslogConfig syslogConfig = new SSLTCPNetSyslogConfig(hostname, port);
    syslogConfig.setIdent(ident);
    syslogConfig.setMaxMessageLength(128000);
    syslogConfig.setSendLocalTimestamp(false);
    syslogConfig.setSendLocalName(false);

    final Syslog4jAppender<ILoggingEvent> syslog4jAppender = new Syslog4jAppender<>();
    syslog4jAppender.setSyslogConfig(syslogConfig);
    syslog4jAppender.setLayout(patternLayout);
    syslog4jAppender.start();

    final Logger logger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);

    logger.addAppender(syslog4jAppender);
    logger.setLevel(Level.DEBUG);
    logger.setAdditive(true); /* set to true if root should log too */
}
 
開發者ID:suomenriistakeskus,項目名稱:oma-riista-web,代碼行數:26,代碼來源:PapertrailConfig.java

示例3: callerData

import ch.qos.logback.classic.PatternLayout; //導入依賴的package包/類
@Test
public void callerData() {
  assertEquals(0, listAppender.list.size());

  PatternLayout pl = new PatternLayout();
  pl.setPattern("%-5level [%class] %logger - %msg");
  pl.setContext(lc);
  pl.start();
  listAppender.layout = pl;

  Logger logger = Logger.getLogger("basic-test");
  logger.trace("none");
  assertEquals(0, listAppender.list.size());
  
  rootLogger.setLevel(Level.TRACE);
  logger.trace(HELLO);
  assertEquals(1, listAppender.list.size());

  ILoggingEvent event = (ILoggingEvent) listAppender.list.get(0);
  assertEquals(HELLO, event.getMessage());

  assertEquals(1, listAppender.stringList.size());
  assertEquals("TRACE [" + Log4jInvocation.class.getName()
      + "] basic-test - Hello", listAppender.stringList.get(0));
}
 
開發者ID:cscfa,項目名稱:bartleby,代碼行數:26,代碼來源:Log4jInvocation.java

示例4: integration

import ch.qos.logback.classic.PatternLayout; //導入依賴的package包/類
@Test
public void integration() {
  PatternLayout pl = new PatternLayout();
  pl.setContext(lc);
  pl.setPattern("%m%n");
  pl.start();
  ILoggingEvent e = createLoggingEvent(new Exception("x"));
  String res = pl.doLayout(e);

  // make sure that at least some package data was output
  Pattern p = Pattern.compile("\\s*at .*?\\[.*?\\]");
  Matcher m = p.matcher(res);
  int i = 0;
  while(m.find()) {
    i++;
  }
  assertTrue(i+ " should be larger than 5", i > 5);
}
 
開發者ID:cscfa,項目名稱:bartleby,代碼行數:19,代碼來源:ExtendedThrowableProxyConverterTest.java

示例5: integration

import ch.qos.logback.classic.PatternLayout; //導入依賴的package包/類
@Test
public void integration() {
  //given
  PatternLayout pl = new PatternLayout();
  pl.setContext(context);
  pl.setPattern("%m%rEx%n");
  pl.start();

  //when
  ILoggingEvent e = createLoggingEvent(new Exception("x"));
  String result = pl.doLayout(e);

  //then
  // make sure that at least some package data was output
  Pattern p = Pattern.compile("\\s*at .*?\\[.*?\\]");
  Matcher m = p.matcher(result);
  int i = 0;
  while(m.find()) {
    i++;
  }
  assertThat(i).isGreaterThan(5);
}
 
開發者ID:cscfa,項目名稱:bartleby,代碼行數:23,代碼來源:RootCauseFirstThrowableProxyConverterTest.java

示例6: doFailSafeConfiguration

import ch.qos.logback.classic.PatternLayout; //導入依賴的package包/類
private void doFailSafeConfiguration() {
    // Not really fail-safe, just less likely to fail
    final LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
    context.reset();
    Logger rootLogger = context.getLogger(Logger.ROOT_LOGGER_NAME);
    rootLogger.setLevel(Level.INFO);

    ConsoleAppender<ILoggingEvent> appender = new ConsoleAppender<ILoggingEvent>();
    rootLogger.addAppender(appender);
    appender.setContext(context);
    appender.setTarget("System.err");

    PatternLayout layout = new PatternLayout();
    appender.setLayout(layout);
    layout.setPattern("%msg%n%ex");
    layout.setContext(context);

    layout.start();
    appender.start();
}
 
開發者ID:Pushjet,項目名稱:Pushjet-Android,代碼行數:21,代碼來源:LogbackLoggingConfigurer.java

示例7: start

import ch.qos.logback.classic.PatternLayout; //導入依賴的package包/類
@Override
public void start()
{
    if (isStarted()) {
        return;
    }

    PatternLayout patternLayout = new PatternLayout();
    patternLayout.setContext(context);
    patternLayout.setPattern(PATTERN);
    patternLayout.setOutputPatternAsHeader(false);
    patternLayout.start();
    this.layout = patternLayout;

    super.start();
}
 
開發者ID:treasure-data,項目名稱:digdag,代碼行數:17,代碼來源:LogbackTaskContextLoggerBridgeAppender.java

示例8: buildAppender

import ch.qos.logback.classic.PatternLayout; //導入依賴的package包/類
protected Appender buildAppender(String name, String fileName, String pattern) {
    RollingFileAppender appender = new RollingFileAppender();
    appender.setContext(loggerContext);
    appender.setName(name);
    appender.setAppend(true);
    appender.setFile(new File(getLogPath(), fileName).getAbsolutePath());

    TimeBasedRollingPolicy rolling = new TimeBasedRollingPolicy();
    rolling.setParent(appender);
    rolling.setFileNamePattern(new File(getLogPath(), fileName).getAbsolutePath() + ".%d{yyyy-MM-dd}");
    rolling.setContext(loggerContext);
    rolling.start();
    appender.setRollingPolicy(rolling);

    PatternLayout layout = new PatternLayout();
    layout.setPattern(pattern);
    layout.setContext(loggerContext);
    layout.start();
    appender.setLayout(layout);
    // 啟動
    appender.start();
    return appender;
}
 
開發者ID:loye168,項目名稱:tddl5,代碼行數:24,代碼來源:DynamicLogback918Logger.java

示例9: buildDailyMaxRollingAppender

import ch.qos.logback.classic.PatternLayout; //導入依賴的package包/類
protected Appender buildDailyMaxRollingAppender(String name, String fileName, String pattern, int maxBackupIndex) {
    RollingFileAppender appender = new RollingFileAppender();
    appender.setContext(loggerContext);
    appender.setName(name);
    appender.setAppend(true);
    appender.setFile(new File(getLogPath(), fileName).getAbsolutePath());

    TimeBasedRollingPolicy rolling = new TimeBasedRollingPolicy();
    rolling.setContext(loggerContext);
    rolling.setFileNamePattern(new File(getLogPath(), fileName).getAbsolutePath() + ".%d{yyyy-MM-dd-HH}");
    rolling.setMaxHistory(maxBackupIndex);
    rolling.setParent(appender);
    rolling.start();
    appender.setRollingPolicy(rolling);

    PatternLayout layout = new PatternLayout();
    layout.setContext(loggerContext);
    layout.setPattern(pattern);
    layout.start();
    appender.setLayout(layout);
    // 啟動
    appender.start();
    return appender;
}
 
開發者ID:loye168,項目名稱:tddl5,代碼行數:25,代碼來源:DynamicLogback918Logger.java

示例10: getConsoleAppender

import ch.qos.logback.classic.PatternLayout; //導入依賴的package包/類
private ConsoleAppender<ILoggingEvent> getConsoleAppender(final LoggingSettings.Console settings,
                                                                final LoggerContext context) {
    final PatternLayout formatter = getPatternLayout(context);
    formatter.setPattern(settings.getLogFormat());
    formatter.start();

    final ConsoleAppender<ILoggingEvent> appender = new ConsoleAppender<ILoggingEvent>();
    appender.setContext(context);
    appender.setLayout(formatter);

    addThresholdFilter(appender, settings.getThreshold());

    appender.start();

    return appender;
}
 
開發者ID:Metrink,項目名稱:croquet,代碼行數:17,代碼來源:CroquetLoggingFactory.java

示例11: setUp

import ch.qos.logback.classic.PatternLayout; //導入依賴的package包/類
@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    _context = new LoggerContext();
    _context.start();
    _baos = new ByteArrayOutputStream();
    _encoder = new KeyValueEncoder();
    _encoder.setImmediateFlush(true);

    final PatternLayout layout = new PatternLayout();
    layout.setPattern("[%d{dd MMM yyyy HH:mm:ss.SSS,UTC}] %t - %m%n");
    layout.setContext(_context);
    layout.start();
    _encoder.setLayout(layout);
    _encoder.setContext(_context);
    Mockito.doThrow(new RuntimeException("Mocked Failure")).when(_throwingLayout).doLayout(Mockito.any(ILoggingEvent.class));
}
 
開發者ID:ArpNetworking,項目名稱:logback-steno,代碼行數:18,代碼來源:KeyValueEncoderTest.java

示例12: initLogback

import ch.qos.logback.classic.PatternLayout; //導入依賴的package包/類
public static void initLogback() {
    LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();

    StatusManager statusManager = loggerContext.getStatusManager();
    if (statusManager != null) {
        statusManager.add(new InfoStatus("Setting up logger configuration.", loggerContext));
    }

    final PatternLayout layout = new PatternLayout();
    layout.setContext(loggerContext);
    layout.setPattern("%msg%n");
    layout.start();

    AppenderBase<ILoggingEvent> appender = new AppenderBase<ILoggingEvent>() {
        @Override
        protected void append(ILoggingEvent event) {
            String message = layout.doLayout(event);
            LogHelper.appendLogEntry(event.getTimeStamp(), convertLevel(event.getLevel()),
                    event.getLoggerName(), event.getThreadName(), message);
        }
    };
    appender.setContext(loggerContext);
    appender.setName(LOGBACK_APPENDER_NAME);
    appender.start();

    Logger rootLogger = loggerContext.getLogger(Logger.ROOT_LOGGER_NAME);
    rootLogger.addAppender(appender);
}
 
開發者ID:noveogroup,項目名稱:clap,代碼行數:29,代碼來源:LogbackHelper.java

示例13: setUp

import ch.qos.logback.classic.PatternLayout; //導入依賴的package包/類
@Before
public void setUp() {
	PatternLayout.defaultConverterMap.put("crlf",
			CRLFConverter.class.getName());
	// layout = new PatternLayout();

	encoder = new PatternLayoutEncoder();
	encoder.setContext(loggerContext);
	encoder.setPattern("%-4relative [%thread] %-5level %logger{35} - %crlf(%msg)%n");
	encoder.start();

	// Layout layout = new PatternLayout();
	// layout.setEncoder(encoder);

	mockAppender.setContext(loggerContext);
	mockAppender.setEncoder(encoder);
	mockAppender.start();

	LOGGER = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
	LOGGER.addAppender(mockAppender);
}
 
開發者ID:javabeanz,項目名稱:owasp-security-logging,代碼行數:22,代碼來源:CRLFConverterTest.java

示例14: setUp

import ch.qos.logback.classic.PatternLayout; //導入依賴的package包/類
@Before
public void setUp() {
	PatternLayout.defaultConverterMap.put("mask",
			MaskingConverter.class.getName());

	encoder = new PatternLayoutEncoder();
	encoder.setContext(loggerContext);
	encoder.setPattern("%-4relative [%thread] %-5level %logger{35} - %mask%n");
	encoder.start();

	mockAppender.setContext(loggerContext);
	mockAppender.setEncoder(encoder);
	mockAppender.start();

	LOGGER.addAppender(mockAppender);
}
 
開發者ID:javabeanz,項目名稱:owasp-security-logging,代碼行數:17,代碼來源:MaskingConverterTest.java

示例15: addConsoleAppenderIfNotPresent

import ch.qos.logback.classic.PatternLayout; //導入依賴的package包/類
/**
 * Check whether ConsoleAppender was already added
 * @param logger
 * @return true   if it was already added
 *         false  if it does not contain ConsoleAppender
 */
public static void addConsoleAppenderIfNotPresent(Logger logger) {
  boolean isConsoleAppenderAdded = false;
  PatternLayout layout = null;
  Iterator<Appender<ILoggingEvent>> appenderSeries = logger.iteratorForAppenders();
  while (appenderSeries.hasNext()) {
    Appender<ILoggingEvent> appender = (Appender<ILoggingEvent>) appenderSeries.next();
    if (appender instanceof ConsoleAppender) {
      isConsoleAppenderAdded = true;
      break;
    }
  }
  if (!isConsoleAppenderAdded) {
    if (layout == null) {
      layout = LoggerUtil.getPatternLayout(logger.getLoggerContext());
    }
    if (logger.getLevel() == null) {
      logger.setLevel(Level.DEBUG);
    }
    ConsoleAppender<ILoggingEvent> consoleAppender = LoggerUtil.getConsoleAppender(layout,
      logger.getLoggerContext());
    logger.addAppender(consoleAppender);
  }
}
 
開發者ID:apache,項目名稱:lens,代碼行數:30,代碼來源:LensConnectionCommands.java


注:本文中的ch.qos.logback.classic.PatternLayout類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。