本文整理汇总了Java中ch.qos.logback.core.encoder.LayoutWrappingEncoder.setLayout方法的典型用法代码示例。如果您正苦于以下问题:Java LayoutWrappingEncoder.setLayout方法的具体用法?Java LayoutWrappingEncoder.setLayout怎么用?Java LayoutWrappingEncoder.setLayout使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ch.qos.logback.core.encoder.LayoutWrappingEncoder
的用法示例。
在下文中一共展示了LayoutWrappingEncoder.setLayout方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: configure
import ch.qos.logback.core.encoder.LayoutWrappingEncoder; //导入方法依赖的package包/类
@Override
public void configure(final LoggerContext lc) {
final ConsoleAppender<ILoggingEvent> ca = new ConsoleAppender<>();
ca.setContext(lc);
ca.setName("console");
final LayoutWrappingEncoder<ILoggingEvent> encoder = new LayoutWrappingEncoder<>();
encoder.setContext(lc);
final TTLLLayout layout = new TTLLLayout();
layout.setContext(lc);
layout.start();
encoder.setLayout(layout);
ca.setEncoder(encoder);
ca.start();
final Logger rootLogger = lc.getLogger("ROOT");
rootLogger.setLevel(Level.WARN);
rootLogger.addAppender(ca);
}
示例2: configure
import ch.qos.logback.core.encoder.LayoutWrappingEncoder; //导入方法依赖的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);
}
示例3: setupOwnLogger
import ch.qos.logback.core.encoder.LayoutWrappingEncoder; //导入方法依赖的package包/类
private static void setupOwnLogger() {
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
logger = (Logger) LoggerFactory.getLogger(Values.BOT_NAME);
ConsoleAppender<ILoggingEvent> consoleAppender = new ConsoleAppender<>();
consoleAppender.setContext(lc);
consoleAppender.setName("console");
LayoutWrappingEncoder<ILoggingEvent> encoder = new LayoutWrappingEncoder<>();
PatternLayout layout = new PatternLayout();
layout.setPattern("[%d{HH:mm:ss}] [%level] [%logger] %msg%n");
layout.setContext(lc);
layout.start();
encoder.setLayout(layout);
consoleAppender.setEncoder(encoder);
consoleAppender.start();
// disable default appender
logger.setAdditive(false);
// enable custom console appender
logger.addAppender(consoleAppender);
// set logging level
if(a.isDebug()) {
logger.setLevel(Level.DEBUG);
} else {
logger.setLevel(Level.INFO);
}
}
示例4: setLayout
import ch.qos.logback.core.encoder.LayoutWrappingEncoder; //导入方法依赖的package包/类
/**
* レイアウトの設定<br>
* 通常は {@link #setEncoder(Encoder)}を利用する
*
* @param layout {@code <layout>}
*/
public void setLayout(Layout<E> layout) {
LayoutWrappingEncoder<E> lwe = new LayoutWrappingEncoder<>();
lwe.setLayout(layout);
lwe.setContext(this.context);
this.encoder = lwe;
}
示例5: configure
import ch.qos.logback.core.encoder.LayoutWrappingEncoder; //导入方法依赖的package包/类
@Override
public void configure(LoggerContext lc) {
addInfo("Setting up robot logging configuration.");
FileAppender<ILoggingEvent> fa = new FileAppender<>();
fa.setFile("tct.log");
fa.setAppend(true);
ConsoleAppender<ILoggingEvent> ca = new ConsoleAppender<>();
ca.setContext(lc);
ca.setName("console");
fa.setContext(lc);
fa.setName("logfile");
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();
fa.setEncoder(encoder);
fa.start();
Logger rootLogger = lc.getLogger(Logger.ROOT_LOGGER_NAME);
// rootLogger.addAppender(ca);
rootLogger.addAppender(fa);
rootLogger.setLevel(Level.WARN);
}
示例6: setupConsoleLogging
import ch.qos.logback.core.encoder.LayoutWrappingEncoder; //导入方法依赖的package包/类
/**
* Sets up SLF4J logging for {@link System#out} and {@link System#err} at INFO level.
* The logger also logs to {@link ClientSettings#LOGGING_FILE}, with the same format as for the console.
*/
private static void setupConsoleLogging() {
Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
root.setLevel(Level.INFO);
ConsoleAppender<ILoggingEvent> consoleAppender =
(ConsoleAppender<ILoggingEvent>) root.getAppender("console");
LayoutWrappingEncoder<ILoggingEvent> consoleWrappingEncoder =
(LayoutWrappingEncoder<ILoggingEvent>) consoleAppender.getEncoder();
LayoutWrappingEncoder<ILoggingEvent> encoder = new LayoutWrappingEncoder<>();
encoder.setLayout(consoleWrappingEncoder.getLayout());
encoder.setCharset(Charset.forName("UTF-16"));
encoder.setContext(root.getLoggerContext());
encoder.start();
FileAppender<ILoggingEvent> logFileAppender = new FileAppender<>();
logFileAppender.setFile(ClientSettings.LOGGING_FILE);
logFileAppender.setContext(root.getLoggerContext());
logFileAppender.setEncoder(encoder);
logFileAppender.setAppend(false);
logFileAppender.start();
root.addAppender(logFileAppender);
SysOutOverSLF4J.sendSystemOutAndErrToSLF4J();
}
示例7: setLayout
import ch.qos.logback.core.encoder.LayoutWrappingEncoder; //导入方法依赖的package包/类
public void setLayout(Layout<E> layout) {
addWarn("This appender no longer admits a layout as a sub-component, set an encoder instead.");
addWarn("To ensure compatibility, wrapping your layout in LayoutWrappingEncoder.");
addWarn("See also "+CODES_URL+"#layoutInsteadOfEncoder for details");
LayoutWrappingEncoder<E> lwe = new LayoutWrappingEncoder<E>();
lwe.setLayout(layout);
lwe.setContext(context);
this.encoder = lwe;
}
示例8: headerFooterCheck
import ch.qos.logback.core.encoder.LayoutWrappingEncoder; //导入方法依赖的package包/类
public void headerFooterCheck(String fileHeader, String presentationHeader, String presentationFooter, String fileFooter) {
OutputStreamAppender<Object> wa = new OutputStreamAppender<Object>();
wa.setContext(context);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
SamplePatternLayout<Object> spl = new SamplePatternLayout<Object>();
spl.setContext(context);
spl.setFileHeader(fileHeader);
spl.setPresentationHeader(presentationHeader);
spl.setPresentationFooter(presentationFooter);
spl.setFileFooter(fileFooter);
spl.start();
LayoutWrappingEncoder<Object> encoder = new LayoutWrappingEncoder<Object>();
encoder.setLayout(spl);
encoder.setContext(context);
wa.setEncoder(encoder);
wa.setOutputStream(baos);
wa.start();
wa.stop();
String result = baos.toString();
String expectedHeader = emtptyIfNull(fileHeader) + emtptyIfNull(presentationHeader);
System.out.println(result);
assertTrue(result, result.startsWith(expectedHeader));
String expectedFooter = emtptyIfNull(presentationFooter) + emtptyIfNull(fileFooter);
assertTrue(result, result.endsWith(expectedFooter));
}
示例9: createAppender
import ch.qos.logback.core.encoder.LayoutWrappingEncoder; //导入方法依赖的package包/类
@Override
public Appender<ILoggingEvent> createAppender(LoggerContext context, String defaultLogFormat) {
LayoutWrappingEncoder<ILoggingEvent> encoder = new LayoutWrappingEncoder<>();
encoder.setLayout(createLayout(context, defaultLogFormat));
FileAppender<ILoggingEvent> appender = (rollingPolicy == null)
? createSingleFileAppender(encoder, context)
: createRollingFileAppender(encoder, context, rollingPolicy);
return asAsync(appender);
}
示例10: createConsoleAppender
import ch.qos.logback.core.encoder.LayoutWrappingEncoder; //导入方法依赖的package包/类
protected ConsoleAppender<ILoggingEvent> createConsoleAppender(LoggerContext context, String defaultLogFormat) {
ConsoleAppender<ILoggingEvent> appender = new ConsoleAppender<>();
appender.setName("console");
appender.setContext(context);
appender.setTarget(target.getLogbackTarget());
LayoutWrappingEncoder<ILoggingEvent> layoutEncoder = new LayoutWrappingEncoder<>();
layoutEncoder.setLayout(createLayout(context, defaultLogFormat));
appender.setEncoder(layoutEncoder);
appender.start();
return appender;
}
示例11: PhialLogger
import ch.qos.logback.core.encoder.LayoutWrappingEncoder; //导入方法依赖的package包/类
/**
* Creates Logger that will write logs in html file using slf4j and logback.
* The logs will be included in Phial Attachment
*
* @param context application context
*/
public PhialLogger(Context context) {
logDir = createLogDir(context);
clearOldLogs(logDir);
final String logDirectory = logDir.getAbsolutePath();
// reset the default context (which may already have been initialized)
// since we want to reconfigure it
LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
loggerContext.reset();
RollingFileAppender<ILoggingEvent> rollingFileAppender = new RollingFileAppender<>();
rollingFileAppender.setContext(loggerContext);
rollingFileAppender.setAppend(true);
rollingFileAppender.setFile(logDirectory + "/" + LOG_PREFIX + "-latest.html");
SizeAndTimeBasedFNATP<ILoggingEvent> fileNamingPolicy = new SizeAndTimeBasedFNATP<>();
fileNamingPolicy.setContext(loggerContext);
fileNamingPolicy.setMaxFileSize(MAX_FILE_SIZE);
TimeBasedRollingPolicy<ILoggingEvent> rollingPolicy = new TimeBasedRollingPolicy<>();
rollingPolicy.setContext(loggerContext);
rollingPolicy.setFileNamePattern(logDirectory + "/" + LOG_PREFIX + HISTORY_FILE_NAME_PATTERN);
rollingPolicy.setMaxHistory(5);
rollingPolicy.setTimeBasedFileNamingAndTriggeringPolicy(fileNamingPolicy);
rollingPolicy.setParent(rollingFileAppender); // parent and context required!
rollingPolicy.start();
HTMLLayout htmlLayout = new HTMLLayout();
htmlLayout.setContext(loggerContext);
htmlLayout.setPattern(PATTERN);
htmlLayout.start();
LayoutWrappingEncoder<ILoggingEvent> encoder = new LayoutWrappingEncoder<>();
encoder.setContext(loggerContext);
encoder.setLayout(htmlLayout);
encoder.start();
rollingFileAppender.setRollingPolicy(rollingPolicy);
rollingFileAppender.setEncoder(encoder);
rollingFileAppender.start();
// add the newly created appenders to the root logger;
// qualify Logger to disambiguate from org.slf4j.Logger
Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
root.setLevel(Level.DEBUG);
root.addAppender(rollingFileAppender);
// print any status messages (warnings, etc) encountered in logback config
StatusPrinter.print(loggerContext);
}
示例12: setLayout
import ch.qos.logback.core.encoder.LayoutWrappingEncoder; //导入方法依赖的package包/类
public final void setLayout(Layout<E> layout) {
LayoutWrappingEncoder<E> enc = new LayoutWrappingEncoder<>();
enc.setLayout(layout);
setEncoder(enc);
}