当前位置: 首页>>代码示例>>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;未经允许,请勿转载。