本文整理汇总了Java中ch.qos.logback.classic.PatternLayout.setPattern方法的典型用法代码示例。如果您正苦于以下问题:Java PatternLayout.setPattern方法的具体用法?Java PatternLayout.setPattern怎么用?Java PatternLayout.setPattern使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ch.qos.logback.classic.PatternLayout
的用法示例。
在下文中一共展示了PatternLayout.setPattern方法的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);
}
示例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 */
}
示例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));
}
示例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);
}
示例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);
}
示例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();
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}
示例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));
}
示例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);
}
示例13: configureLogging
import ch.qos.logback.classic.PatternLayout; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public static void configureLogging(Level level) {
ch.qos.logback.classic.Logger valverlog = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Version.class);
valverlog.setLevel(ERROR);
ch.qos.logback.classic.Logger reflog = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Reflections.class);
reflog.setLevel(ERROR);
ch.qos.logback.classic.Logger logger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger("ROOT");
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
ConsoleAppender console = (ConsoleAppender) logger.getAppender("console");
logger.setLevel(level);
console.stop();
PatternLayout pl = new PatternLayout();
pl.setPattern("%r %5p [%X{resource}] %m%n%nopex");
pl.setContext(lc);
pl.start();
console.setLayout(pl);
console.start();
}
示例14: createAppender
import ch.qos.logback.classic.PatternLayout; //导入方法依赖的package包/类
private FlumeAppender createAppender(final Agent... agents) {
PatternLayout layout = new PatternLayout();
layout.setContext(ctx);
layout.setPattern("%d{yyyy-MM-dd HH:mm:ss} %c [%p] %m%n");
layout.start();
final FlumeAppender avroAppender = new FlumeAppender();
if (null == agents || agents.length == 0) {
avroAppender.addAgent(Agent.create("localhost", testPort));
} else {
for (Agent agent : agents) {
avroAppender.addAgent(agent);
}
}
avroAppender.setCompressBody(true);
avroAppender.setType("avro");
avroAppender.setLayout(layout);
avroAppender.setName("FlumeAppender");
avroAppender.start();
return avroAppender;
}
示例15: start
import ch.qos.logback.classic.PatternLayout; //导入方法依赖的package包/类
@Override
public void start() {
patternLayout = new PatternLayout();
patternLayout.setContext(getContext());
patternLayout.setPattern("[`%d{HH:mm:ss}`] [`%t/%level`] [`%logger{0}`]: %msg");
patternLayout.start();
super.start();
}