本文整理汇总了Java中ch.qos.logback.core.encoder.Encoder类的典型用法代码示例。如果您正苦于以下问题:Java Encoder类的具体用法?Java Encoder怎么用?Java Encoder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Encoder类属于ch.qos.logback.core.encoder包,在下文中一共展示了Encoder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testAbstractAndConsole
import ch.qos.logback.core.encoder.Encoder; //导入依赖的package包/类
/**
* Test abstract functions (using console implementation) and the functions
* of console
*
*/
@Test
public void testAbstractAndConsole() {
BaleenConsoleLoggerBuilder builder = new BaleenConsoleLoggerBuilder(NAME, BaleenLogging.DEFAULT_PATTERN,
new MinMaxFilter(Level.INFO, Level.WARN));
LoggerContext context = new LoggerContext();
Encoder<ILoggingEvent> encoder = new PatternLayoutEncoder();
Appender<ILoggingEvent> appender = builder.build(context, encoder);
assertEquals(NAME, builder.getName());
assertTrue(appender instanceof ConsoleAppender);
assertEquals(encoder, ((ConsoleAppender<ILoggingEvent>) appender).getEncoder());
assertNotNull(appender);
assertEquals(NAME, appender.getName());
Filter<ILoggingEvent> filter = appender.getCopyOfAttachedFiltersList().get(0);
assertTrue(filter instanceof MinMaxFilter);
assertEquals(Level.INFO, ((MinMaxFilter) filter).getMin());
assertEquals(Level.WARN, ((MinMaxFilter) filter).getMax());
}
示例2: createRollingFileAppender
import ch.qos.logback.core.encoder.Encoder; //导入依赖的package包/类
protected FileAppender<ILoggingEvent> createRollingFileAppender(Encoder<ILoggingEvent> encoder,
LoggerContext context,
RollingPolicyFactory rollingPolicy) {
RollingFileAppender<ILoggingEvent> appender = new RollingFileAppender<>();
appender.setFile(file);
appender.setContext(context);
appender.setEncoder(encoder);
// Setup rolling policy
RollingPolicy policy = rollingPolicy.createRollingPolicy(context);
appender.setRollingPolicy(policy);
policy.setParent(appender);
// Setup triggering policy
TriggeringPolicy<ILoggingEvent> triggeringPolicy = rollingPolicy.createTriggeringPolicy(context);
if (triggeringPolicy != null) {
appender.setTriggeringPolicy(triggeringPolicy);
triggeringPolicy.start();
}
policy.start();
appender.start();
return appender;
}
示例3: logToFile
import ch.qos.logback.core.encoder.Encoder; //导入依赖的package包/类
/**
* Configure file logging and stop console logging.
*
* @param filename
* Log to this file.
*/
@SuppressWarnings("unchecked")
static void logToFile(String filename) {
Logger rootLogger = (Logger) LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
FileAppender<ILoggingEvent> fileappender = new FileAppender<>();
fileappender.setContext(rootLogger.getLoggerContext());
fileappender.setFile(filename);
fileappender.setName("FILE");
ConsoleAppender<?> console = (ConsoleAppender<?>) rootLogger.getAppender("STDOUT");
fileappender.setEncoder((Encoder<ILoggingEvent>) console.getEncoder());
fileappender.start();
rootLogger.addAppender(fileappender);
console.stop();
}
示例4: consolePatternCanBeOverridden
import ch.qos.logback.core.encoder.Encoder; //导入依赖的package包/类
@Test
public void consolePatternCanBeOverridden() throws JoranException {
JoranConfigurator configurator = new JoranConfigurator();
LoggerContext context = new LoggerContext();
configurator.setContext(context);
configurator.doConfigure(
new File("src/test/resources/custom-console-log-pattern.xml"));
Appender<ILoggingEvent> appender = context.getLogger("ROOT")
.getAppender("CONSOLE");
assertThat(appender).isInstanceOf(ConsoleAppender.class);
Encoder<?> encoder = ((ConsoleAppender<?>) appender).getEncoder();
assertThat(encoder).isInstanceOf(PatternLayoutEncoder.class);
assertThat(((PatternLayoutEncoder) encoder).getPattern()).isEqualTo("foo");
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:15,代码来源:LogbackConfigurationTests.java
示例5: setImmediateFlush
import ch.qos.logback.core.encoder.Encoder; //导入依赖的package包/类
public boolean setImmediateFlush(boolean enable) {
FileAppender<ILoggingEvent> fileLogger = getFileLogger();
Encoder<ILoggingEvent> encoder = fileLogger.getEncoder();
if (encoder instanceof LayoutWrappingEncoder) {
((LayoutWrappingEncoder) encoder).setImmediateFlush(enable);
return true;
}
return false;
}
示例6: isImmediateFlush
import ch.qos.logback.core.encoder.Encoder; //导入依赖的package包/类
public boolean isImmediateFlush() {
FileAppender<ILoggingEvent> fileLogger = getFileLogger();
Encoder<ILoggingEvent> encoder = fileLogger.getEncoder();
if (encoder instanceof LayoutWrappingEncoder) {
return ((LayoutWrappingEncoder) encoder).isImmediateFlush();
}
return false;
}
示例7: testBasic
import ch.qos.logback.core.encoder.Encoder; //导入依赖的package包/类
@Test
public void testBasic() throws IOException {
Encoder<Object> encoder = new DummyEncoder<Object>();
encoder.init(baos);
da.setEncoder(encoder);
da.start();
da.doAppend(new Object());
assertEquals(DummyLayout.DUMMY, baos.toString());
}
示例8: setEncoder
import ch.qos.logback.core.encoder.Encoder; //导入依赖的package包/类
public synchronized void setEncoder(final Encoder<E> encoder) {
if (isStarted()) {
addStatus(new ErrorStatus("Cannot configure appender named \"" + this.name
+ "\" after it has been started.", this));
}
this.encoder = encoder;
}
示例9: createDailyLogAppender
import ch.qos.logback.core.encoder.Encoder; //导入依赖的package包/类
/**
* Create an appender that will create a new log each day
*
* @param context
* @param encoder
* @return An appender that matches the set up of the logger builder
*/
private RollingFileAppender<ILoggingEvent> createDailyLogAppender(LoggerContext context, Encoder<ILoggingEvent> encoder){
RollingFileAppender<ILoggingEvent> appender = new RollingFileAppender<>();
appender.setEncoder(encoder);
appender.setFile(file);
TimeBasedRollingPolicy<ILoggingEvent> rolling = new TimeBasedRollingPolicy<>();
rolling.setContext(context);
rolling.setParent(appender);
rolling.setFileNamePattern(getFileWithPattern("%d"));
//Set the maximum number of logs, either to the user specified setting or default to 1
if (maxNumberLogs.isPresent() && maxNumberLogs.get() >= 0) {
rolling.setMaxHistory(maxNumberLogs.get());
} else {
rolling.setMaxHistory(1);
}
//Do we need to also split files by size?
if (divideBasedOnSize()) {
SizeAndTimeBasedFNATP<ILoggingEvent> sizeBased = new SizeAndTimeBasedFNATP<>();
sizeBased.setContext(context);
sizeBased.setMaxFileSize(getMaxFileSize());
sizeBased.setTimeBasedRollingPolicy(rolling);
rolling.setTimeBasedFileNamingAndTriggeringPolicy(sizeBased);
}
rolling.start();
if(rolling.getTimeBasedFileNamingAndTriggeringPolicy() != null){
rolling.getTimeBasedFileNamingAndTriggeringPolicy().start();
}
appender.setRollingPolicy(rolling);
return appender;
}
示例10: createLogAppender
import ch.qos.logback.core.encoder.Encoder; //导入依赖的package包/类
/**
* Create an appender that will roll over based on size
*
* @param context
* @param encoder
* @return An appender that matches the set up of the logger builder
*/
private RollingFileAppender<ILoggingEvent> createLogAppender(LoggerContext context, Encoder<ILoggingEvent> encoder){
RollingFileAppender<ILoggingEvent> appender = new RollingFileAppender<>();
appender.setEncoder(encoder);
appender.setFile(file);
FixedWindowRollingPolicy rolling = new FixedWindowRollingPolicy();
rolling.setParent(appender);
rolling.setContext(context);
//Set the maximum number of logs, either to the user specified setting or default to 1
rolling.setMinIndex(1);
if (maxNumberLogs.isPresent() && maxNumberLogs.get() >= 0) {
rolling.setMaxIndex(maxNumberLogs.get());
} else {
rolling.setMaxIndex(1);
}
rolling.setFileNamePattern(getFileWithPattern("%i"));
//Configure size based rolling
SizeBasedTriggeringPolicy<ILoggingEvent> trigger = new SizeBasedTriggeringPolicy<>();
trigger.setMaxFileSize(getMaxFileSize());
trigger.setContext(context);
rolling.start();
trigger.start();
appender.setRollingPolicy(rolling);
appender.setTriggeringPolicy(trigger);
return appender;
}
示例11: build
import ch.qos.logback.core.encoder.Encoder; //导入依赖的package包/类
/**
* Build a new appender for the specified context and encoder (where required).
*
* @param context The logger context
* @param encoder The encoder to use (if that is possible for the specific appender)
* @return The new appender
*/
@Override
public final Appender<ILoggingEvent> build(LoggerContext context, Encoder<ILoggingEvent> encoder) {
Appender<ILoggingEvent> appender = createAppender(context, encoder);
appender.setName(name);
appender.setContext(context);
if (filters != null) {
filters.forEach(f -> appender.addFilter(f));
}
return appender;
}
示例12: test
import ch.qos.logback.core.encoder.Encoder; //导入依赖的package包/类
@Test
public void test() {
BaleenLogging logging = new BaleenLogging();
InMemoryLoggingBuilder builder = new InMemoryLoggingBuilder();
logging.configure(Arrays.asList(builder, new BaleenConsoleLoggerBuilder(PATTERN, new MinMaxFilter(Level.INFO,
Level.ERROR))));
LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
Logger rootLogger = context.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME);
int count = 0;
Iterator<Appender<ILoggingEvent>> it = rootLogger.iteratorForAppenders();
while (it.hasNext()) {
Appender<ILoggingEvent> appender = it.next();
if (appender instanceof OutputStreamAppender) {
Encoder<ILoggingEvent> e = ((OutputStreamAppender<ILoggingEvent>) appender).getEncoder();
assertTrue(e instanceof PatternLayoutEncoder);
assertEquals(PATTERN, ((PatternLayoutEncoder) e).getPattern());
}
count++;
}
// 3 = 2 + instrumented appender
assertEquals(3, count);
}
示例13: testAbstractAndConsoleMultipleFilters
import ch.qos.logback.core.encoder.Encoder; //导入依赖的package包/类
@Test
public void testAbstractAndConsoleMultipleFilters() {
BaleenConsoleLoggerBuilder builder = new BaleenConsoleLoggerBuilder(NAME, BaleenLogging.DEFAULT_PATTERN,
Arrays.asList(new MinMaxFilter(Level.INFO, Level.ERROR), new MinMaxFilter(Level.INFO, Level.WARN)));
LoggerContext context = new LoggerContext();
Encoder<ILoggingEvent> encoder = new PatternLayoutEncoder();
Appender<ILoggingEvent> appender = builder.build(context, encoder);
assertEquals(NAME, builder.getName());
assertTrue(appender instanceof ConsoleAppender);
assertEquals(encoder, ((ConsoleAppender<ILoggingEvent>) appender).getEncoder());
assertNotNull(appender);
assertEquals(NAME, appender.getName());
assertEquals(2, appender.getCopyOfAttachedFiltersList().size());
Filter<ILoggingEvent> filter = appender.getCopyOfAttachedFiltersList().get(0);
assertTrue(filter instanceof MinMaxFilter);
assertEquals(Level.INFO, ((MinMaxFilter) filter).getMin());
assertEquals(Level.ERROR, ((MinMaxFilter) filter).getMax());
filter = appender.getCopyOfAttachedFiltersList().get(1);
assertTrue(filter instanceof MinMaxFilter);
assertEquals(Level.INFO, ((MinMaxFilter) filter).getMin());
assertEquals(Level.WARN, ((MinMaxFilter) filter).getMax());
// TODO: Test that both filters are being applied
}
示例14: testFileWithDailyRolling
import ch.qos.logback.core.encoder.Encoder; //导入依赖的package包/类
@Test
public void testFileWithDailyRolling() {
BaleenFileLoggerBuilder builder = new BaleenFileLoggerBuilder(NAME, BaleenLogging.DEFAULT_PATTERN,
LOG_FILENAME, new MinMaxFilter(Level.INFO, Level.WARN), true, Optional.of(5), Optional.of(10));
LoggerContext context = new LoggerContext();
Encoder<ILoggingEvent> encoder = new PatternLayoutEncoder();
Appender<ILoggingEvent> appender = builder.build(context, encoder);
assertTrue(appender instanceof FileAppender);
assertEquals(encoder, ((FileAppender<ILoggingEvent>) appender).getEncoder());
// TODO: Add tests on the (current private) methods
}
示例15: testFileWithDailyRollingWithoutSize
import ch.qos.logback.core.encoder.Encoder; //导入依赖的package包/类
@Test
public void testFileWithDailyRollingWithoutSize() {
BaleenFileLoggerBuilder builder = new BaleenFileLoggerBuilder(NAME, BaleenLogging.DEFAULT_PATTERN,
LOG_FILENAME, new MinMaxFilter(Level.INFO, Level.WARN), true, Optional.empty(), Optional.of(10));
LoggerContext context = new LoggerContext();
Encoder<ILoggingEvent> encoder = new PatternLayoutEncoder();
Appender<ILoggingEvent> appender = builder.build(context, encoder);
assertTrue(appender instanceof FileAppender);
assertEquals(encoder, ((FileAppender<ILoggingEvent>) appender).getEncoder());
// TODO: Add tests on the (current private) methods
}