• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Encoder类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中ch.qos.logback.core.encoder.Encoder的典型用法代码示例。如果您正苦于以下问题:Java Encoder类的具体用法?Java Encoder怎么用?Java Encoder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Encoder类属于ch.qos.logback.core.encoder包,在下文中一共展示了Encoder类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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());
}
 
开发者ID:dstl,项目名称:baleen,代码行数:28,代码来源:BaleenLoggerBuilderTest.java


示例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;
}
 
开发者ID:bootique,项目名称:bootique-logback,代码行数:24,代码来源:FileAppenderFactory.java


示例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();
}
 
开发者ID:aminmf,项目名称:crawljax,代码行数:25,代码来源:LogUtil.java


示例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;
}
 
开发者ID:scifiswapnil,项目名称:gadgetbridge_artikcloud,代码行数:10,代码来源:Logging.java


示例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;
}
 
开发者ID:scifiswapnil,项目名称:gadgetbridge_artikcloud,代码行数:9,代码来源:Logging.java


示例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());
}
 
开发者ID:cscfa,项目名称:bartleby,代码行数:10,代码来源:DummyAppenderTest.java


示例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;
}
 
开发者ID:dkmfbk,项目名称:knowledgestore,代码行数:8,代码来源:Logging.java


示例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;
}
 
开发者ID:dstl,项目名称:baleen,代码行数:44,代码来源:BaleenFileLoggerBuilder.java


示例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;
}
 
开发者ID:dstl,项目名称:baleen,代码行数:38,代码来源:BaleenFileLoggerBuilder.java


示例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;
}
 
开发者ID:dstl,项目名称:baleen,代码行数:20,代码来源:AbstractBaleenLoggerBuilder.java


示例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);

}
 
开发者ID:dstl,项目名称:baleen,代码行数:31,代码来源:BaleenLoggingTest.java


示例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
}
 
开发者ID:dstl,项目名称:baleen,代码行数:31,代码来源:BaleenLoggerBuilderTest.java


示例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
}
 
开发者ID:dstl,项目名称:baleen,代码行数:16,代码来源:BaleenLoggerBuilderTest.java


示例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
}
 
开发者ID:dstl,项目名称:baleen,代码行数:16,代码来源:BaleenLoggerBuilderTest.java


示例16: testFileWithoutDailyRolling

import ch.qos.logback.core.encoder.Encoder; //导入依赖的package包/类
@Test
public void testFileWithoutDailyRolling() {
	BaleenFileLoggerBuilder builder = new BaleenFileLoggerBuilder(NAME, BaleenLogging.DEFAULT_PATTERN,
			LOG_FILENAME, new MinMaxFilter(Level.INFO, Level.WARN), false, 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
}
 
开发者ID:dstl,项目名称:baleen,代码行数:16,代码来源:BaleenLoggerBuilderTest.java


示例17: getEncoding

import ch.qos.logback.core.encoder.Encoder; //导入依赖的package包/类
@Override
public String getEncoding() {
  if (getTarget() instanceof OutputStreamAppender) {
    OutputStreamAppender<?> appender = (OutputStreamAppender<?>) getTarget();
    Encoder<?> encoder = appender.getEncoder();
    if (encoder instanceof LayoutWrappingEncoder) {
      LayoutWrappingEncoder<?> base = (LayoutWrappingEncoder<?>) encoder;
      if (base.getCharset() != null) {
        return base.getCharset().name();
      }
      return null;
    }
  }
  return null;
}
 
开发者ID:psi-probe,项目名称:psi-probe,代码行数:16,代码来源:LogbackAppenderAccessor.java


示例18: createSingleFileAppender

import ch.qos.logback.core.encoder.Encoder; //导入依赖的package包/类
protected FileAppender<ILoggingEvent> createSingleFileAppender(Encoder<ILoggingEvent> encoder,
                                                               LoggerContext context) {
    FileAppender<ILoggingEvent> appender = new FileAppender<>();
    appender.setFile(Objects.requireNonNull(file));

    appender.setContext(context);
    appender.setEncoder(encoder);
    appender.start();

    return appender;
}
 
开发者ID:bootique,项目名称:bootique-logback,代码行数:12,代码来源:FileAppenderFactory.java


示例19: setupAppender

import ch.qos.logback.core.encoder.Encoder; //导入依赖的package包/类
private ConsoleAppender setupAppender(String target, LoggerContext ctx, Encoder enc) {
    ConsoleAppender appender = new ConsoleAppender();
    appender.setTarget(target);
    appender.setContext(ctx);
    appender.setEncoder(enc);

    appender.start();

    return appender;
}
 
开发者ID:Evolveum,项目名称:midpoint,代码行数:11,代码来源:Log.java


示例20: getPatternLayoutEncoder

import ch.qos.logback.core.encoder.Encoder; //导入依赖的package包/类
private static Encoder<ILoggingEvent> getPatternLayoutEncoder(String logPattern) {
       PatternLayoutEncoder patternLayoutEncoder = new PatternLayoutEncoder();
       patternLayoutEncoder.setPattern(logPattern);
       patternLayoutEncoder.setContext(loggerContext);
       patternLayoutEncoder.setOutputPatternAsHeader(true);
       patternLayoutEncoder.start();

       return patternLayoutEncoder;
}
 
开发者ID:sangupta,项目名称:jerry-core,代码行数:10,代码来源:ApplicationLogger.java



注:本文中的ch.qos.logback.core.encoder.Encoder类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java MifareClassic类代码示例发布时间:2022-05-21
下一篇:
Java PeekMetrics类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap