本文整理汇总了Java中ch.qos.logback.core.OutputStreamAppender.setOutputStream方法的典型用法代码示例。如果您正苦于以下问题:Java OutputStreamAppender.setOutputStream方法的具体用法?Java OutputStreamAppender.setOutputStream怎么用?Java OutputStreamAppender.setOutputStream使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ch.qos.logback.core.OutputStreamAppender
的用法示例。
在下文中一共展示了OutputStreamAppender.setOutputStream方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: configureInMemoryLogging
import ch.qos.logback.core.OutputStreamAppender; //导入方法依赖的package包/类
private static void configureInMemoryLogging() {
org.slf4j.Logger rootLogger = LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
Logger logbackRootLogger = (Logger) rootLogger;
logbackRootLogger.setLevel(Level.INFO);
OutputStreamAppender<ILoggingEvent> appender = new OutputStreamAppender<>();
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
PatternLayoutEncoder ple = new PatternLayoutEncoder();
ple.setPattern("[%date] [%level] [%logger{10}] %msg%n");
ple.setContext(lc);
ple.start();
try {
ple.init(bos);
} catch (IOException e) {
}
appender.setContext(lc);
appender.setOutputStream(bos);
appender.setName("buffered");
appender.setEncoder(ple);
appender.start();
logbackRootLogger.detachAppender("console");
logbackRootLogger.addAppender(appender);
logbackRootLogger.setAdditive(true);
}
示例2: testLogStatisticsStore
import ch.qos.logback.core.OutputStreamAppender; //导入方法依赖的package包/类
/**
* Test log statistics store.
*
* @throws Exception the exception
*/
@Test
public void testLogStatisticsStore() throws Exception {
LogStatisticsStore store = new LogStatisticsStore();
store.initialize(LensServerConf.getHiveConf());
// Do some initialization work
ByteArrayOutputStream writer = new ByteArrayOutputStream();
Logger l = (Logger) LoggerFactory.getLogger(MyLoggableLens.class);
OutputStreamAppender<ILoggingEvent> appender = new OutputStreamAppender<ILoggingEvent>();
appender.setLayout(new StatisticsLogLayout());
appender.setContext(l.getLoggerContext());
appender.setOutputStream(writer);
appender.setName(MyLoggableLens.class.getCanonicalName());
appender.start();
l.addAppender(appender);
MyLoggableLens sampleEvent = new MyLoggableLens(System.currentTimeMillis());
store.process(sampleEvent);
writer.flush();
l.detachAppender(appender);
appender.stop();
ObjectMapper mapper = new ObjectMapper();
String expected = mapper.writeValueAsString(sampleEvent);
Assert.assertEquals(new String(writer.toByteArray(), "UTF-8").trim(), expected.trim());
writer.close();
}
示例3: initializeFor
import ch.qos.logback.core.OutputStreamAppender; //导入方法依赖的package包/类
public LogTester initializeFor(Class<?> klazzFor) {
ByteArrayOutputStream out = new ByteArrayOutputStream();
Logger logger = (Logger)LoggerFactory.getLogger(klazzFor);
LoggerContext ctx = logger.getLoggerContext();
PatternLayoutEncoder encoder = new PatternLayoutEncoder();
encoder.setContext(ctx);
encoder.setPattern("%p:%msg%n");
encoder.start();
OutputStreamAppender<ILoggingEvent> appender = new OutputStreamAppender<ILoggingEvent>();
appender.setContext(ctx);
appender.setEncoder(encoder);
appender.setOutputStream(out);
appender.start();
logger.setLevel(Level.TRACE);
logger.addAppender(appender);
keeper = new LogKeeper(out);
initialized = true;
return this;
}
示例4: createLogViewTab
import ch.qos.logback.core.OutputStreamAppender; //导入方法依赖的package包/类
private Tab createLogViewTab() {
Tab logView = new Tab("log");
TextArea ta = new TextArea();
ta.setWrapText(false);
if(console != null) {
console.exit();
}
console = new Console(ta, lastLogMessage);
ta.setStyle("-fx-font-family: Monospaced;");
PrintStream ps = new PrintStream(console, true);
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
// ch.qos.logback.classic.Logger logger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger("ROOT");
// Limit logs to AEMDC otherwise any logs are printed here
ch.qos.logback.classic.Logger logger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger("com.headwire.aemdc");
// Limit logs to INFO to cut down on number of log statements
logger.setLevel(Level.INFO);
PatternLayoutEncoder ple = new PatternLayoutEncoder();
ple.setPattern("%m%n)");
ple.setContext(lc);
ple.start();
OutputStreamAppender<ILoggingEvent> appender = new OutputStreamAppender<>();
appender.setContext(lc);
appender.setEncoder(ple);
appender.setOutputStream(ps);
appender.start();
logger.addAppender(appender);
logView.setContent(ta);
logView.setClosable(false);
return logView;
}
示例5: createAppender
import ch.qos.logback.core.OutputStreamAppender; //导入方法依赖的package包/类
/**
* Creates an {@link OutputStreamAppender} for the required filter, pattern and logger output.
*
* @param context Logger context to associate the appender with.
* @param filter Event log filter.
* @param logOutput Logger output information for the destination to write logger events to.
* @param patternProperty Logger context property that defines the pattern for formatting logger event output.
* @param name The name of the appender.
* @return An {@link OutputStreamAppender} for the required parameters.
*/
private static OutputStreamAppender<ILoggingEvent> createAppender(LoggerContext context, Filter<ILoggingEvent> filter, LoggerOutput logOutput, String patternProperty, String name) {
final PatternLayoutEncoder patternLayoutEncoder = createPatternLayoutEncoder(context, patternProperty);
final OutputStreamAppender<ILoggingEvent> appender;
if (logOutput.isConsole()) {
appender = new OutputStreamAppender<>();
appender.setContext(context);
appender.setEncoder(patternLayoutEncoder);
appender.setOutputStream(logOutput.getPrintStream());
appender.setName(name);
appender.addFilter(filter);
appender.start();
} else {
RollingFileAppender<ILoggingEvent> rAppender = new RollingFileAppender<>();
rAppender.setContext(context);
rAppender.setEncoder(patternLayoutEncoder);
rAppender.setFile(logOutput.getOutputName()+"."+logOutput.getOutputType());
rAppender.setName(name);
rAppender.addFilter(filter);
final FixedWindowRollingPolicy rollingPolicy = new FixedWindowRollingPolicy();
rollingPolicy.setContext(context);
rollingPolicy.setParent(rAppender);
rollingPolicy.setFileNamePattern(logOutput.getOutputName()+"%i"+"."+logOutput.getOutputType());
rollingPolicy.setMinIndex(1);
rollingPolicy.setMaxIndex(logOutput.getFileCount());
rollingPolicy.start();
final SizeBasedTriggeringPolicy<ILoggingEvent> triggeringPolicy = new SizeBasedTriggeringPolicy<>();
triggeringPolicy.setContext(context);
triggeringPolicy.setMaxFileSize(logOutput.getFileLimit());
triggeringPolicy.start();
rAppender.setRollingPolicy(rollingPolicy);
rAppender.setTriggeringPolicy(triggeringPolicy);
rAppender.start();
appender = rAppender;
}
return appender;
}
示例6: shouldUseTheFilter
import ch.qos.logback.core.OutputStreamAppender; //导入方法依赖的package包/类
@Test public void shouldUseTheFilter() {
// given
// ...the tested filter
DenyDuplicationsFilter filter = new DenyDuplicationsFilter();
filter.setMaxSize(100);
filter.setSecondsBetweenEvictions(100);
filter.setItemMaxAgeInSeconds(30);
// ...logback stopped and ready to work
LoggerContext ctx = (LoggerContext) LoggerFactory.getILoggerFactory();
Logger rootLogger = ctx.getLogger(Logger.ROOT_LOGGER_NAME);
rootLogger.detachAndStopAllAppenders();
// ...an out stream
OutputStream out = new ByteArrayOutputStream();
// ...a pattern layout, pay attention to the format, is important for the test
PatternLayoutEncoder layout = new PatternLayoutEncoder();
layout.setContext(ctx);
layout.setPattern("[%level %msg]");
layout.setImmediateFlush(true);
layout.start();
// ...a console appender that logs through the filter
OutputStreamAppender<ILoggingEvent> appender = new OutputStreamAppender<ILoggingEvent>();
appender.setContext(ctx);
appender.setEncoder(layout);
appender.addFilter( filter );
appender.setOutputStream(out);
appender.start();
// ...a logger we can use for the test
Logger testLogger = ctx.getLogger("test");
testLogger.addAppender(appender);
testLogger.setLevel(Level.ALL);
// when
testLogger.trace("Hello World"); // first occurrence, should be logged
testLogger.debug("Hello World"); // second occurrence, should be filtered out
testLogger.info ("Hello Italy"); // this is new, should be logged
testLogger.error("Hello Italy"); // again a repetition
testLogger.warn ("Hello World"); // again a repetition
testLogger.info ("Hello World"); // again a repetition
// then
appender.stop();
String string = out.toString();
assertThat( string, equalTo("[TRACE Hello World][INFO Hello Italy]") );
}