本文整理汇总了Java中ch.qos.logback.core.OutputStreamAppender类的典型用法代码示例。如果您正苦于以下问题:Java OutputStreamAppender类的具体用法?Java OutputStreamAppender怎么用?Java OutputStreamAppender使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
OutputStreamAppender类属于ch.qos.logback.core包,在下文中一共展示了OutputStreamAppender类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: configure
import ch.qos.logback.core.OutputStreamAppender; //导入依赖的package包/类
/**
* Initializes the logger and the requested log level.
*
* @param level Logging level threshold
*/
@SuppressWarnings("unchecked")
public static void configure(final Level level) {
final Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
root.setLevel(level);
PatternLayoutEncoder encoder = new PatternLayoutEncoder();
encoder.setContext(root.getLoggerContext());
encoder.setPattern("%msg%n");
encoder.start();
Iterator<Appender<ILoggingEvent>> iterator = root.iteratorForAppenders();
while (iterator.hasNext()) {
Appender<ILoggingEvent> appender = iterator.next();
if (appender instanceof OutputStreamAppender) {
((OutputStreamAppender) appender).setEncoder(encoder);
}
appender.stop();
appender.start();
}
}
示例3: applyLogConfig
import ch.qos.logback.core.OutputStreamAppender; //导入依赖的package包/类
private void applyLogConfig() {
boolean loggingActivated = isSet(TermSuiteCliOption.LOG_INFO)
|| isSet(TermSuiteCliOption.LOG_DEBUG)
|| isSet(TermSuiteCliOption.LOG_TO_FILE);
if(loggingActivated) {
OutputStreamAppender<ILoggingEvent> appender =
isSet(TermSuiteCliOption.LOG_TO_FILE) ?
LogbackUtils.createFileAppender(asPath(TermSuiteCliOption.LOG_TO_FILE)) :
LogbackUtils.createConsoleAppender();
LogbackUtils.activateLogging(appender);
Level level = Level.WARN;
if(isSet(TermSuiteCliOption.LOG_INFO))
level = Level.INFO;
else if(isSet(TermSuiteCliOption.LOG_DEBUG))
level = Level.DEBUG;
else if(isSet(TermSuiteCliOption.LOG_TO_FILE))
level = Level.INFO;
LogbackUtils.setGlobalLogLevel(level);
}
}
示例4: 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();
}
示例5: 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;
}
示例6: configureFileLogging
import ch.qos.logback.core.OutputStreamAppender; //导入依赖的package包/类
private static OutputStreamAppender<ILoggingEvent> configureFileLogging(File logFile, LoggerContext loggerContext) {
RollingFileAppender<ILoggingEvent> rollingFileAppender = new RollingFileAppender<ILoggingEvent>();
rollingFileAppender.setFile(logFile.getAbsolutePath());
rollingFileAppender.setName("com.documents4j.logger.client.file");
rollingFileAppender.setContext(loggerContext);
FixedWindowRollingPolicy fixedWindowRollingPolicy = new FixedWindowRollingPolicy();
fixedWindowRollingPolicy.setFileNamePattern(logFile.getAbsolutePath() + ".%i.gz");
fixedWindowRollingPolicy.setMaxIndex(LogDescription.MAXIMUM_LOG_HISTORY_INDEX);
fixedWindowRollingPolicy.setContext(loggerContext);
fixedWindowRollingPolicy.setParent(rollingFileAppender);
SizeBasedTriggeringPolicy<ILoggingEvent> sizeBasedTriggeringPolicy = new SizeBasedTriggeringPolicy<ILoggingEvent>();
sizeBasedTriggeringPolicy.setMaxFileSize(LogDescription.MAXIMUM_LOG_FILE_SIZE);
sizeBasedTriggeringPolicy.setContext(loggerContext);
rollingFileAppender.setRollingPolicy(fixedWindowRollingPolicy);
rollingFileAppender.setTriggeringPolicy(sizeBasedTriggeringPolicy);
sizeBasedTriggeringPolicy.start();
fixedWindowRollingPolicy.start();
System.out.println("Logging: The log is written to " + logFile);
return rollingFileAppender;
}
示例7: configureFileLogging
import ch.qos.logback.core.OutputStreamAppender; //导入依赖的package包/类
private static OutputStreamAppender<ILoggingEvent> configureFileLogging(File logFile, LoggerContext loggerContext) {
RollingFileAppender<ILoggingEvent> rollingFileAppender = new RollingFileAppender<ILoggingEvent>();
rollingFileAppender.setFile(logFile.getAbsolutePath());
rollingFileAppender.setName("com.documents4j.logger.server.file");
rollingFileAppender.setContext(loggerContext);
FixedWindowRollingPolicy fixedWindowRollingPolicy = new FixedWindowRollingPolicy();
fixedWindowRollingPolicy.setFileNamePattern(logFile.getAbsolutePath() + ".%i.gz");
fixedWindowRollingPolicy.setMaxIndex(LogDescription.MAXIMUM_LOG_HISTORY_INDEX);
fixedWindowRollingPolicy.setContext(loggerContext);
fixedWindowRollingPolicy.setParent(rollingFileAppender);
SizeBasedTriggeringPolicy<ILoggingEvent> sizeBasedTriggeringPolicy = new SizeBasedTriggeringPolicy<ILoggingEvent>();
sizeBasedTriggeringPolicy.setMaxFileSize(LogDescription.MAXIMUM_LOG_FILE_SIZE);
sizeBasedTriggeringPolicy.setContext(loggerContext);
rollingFileAppender.setRollingPolicy(fixedWindowRollingPolicy);
rollingFileAppender.setTriggeringPolicy(sizeBasedTriggeringPolicy);
sizeBasedTriggeringPolicy.start();
fixedWindowRollingPolicy.start();
System.out.println("Logging: The log is written to " + logFile);
return rollingFileAppender;
}
示例8: setVerboseMode
import ch.qos.logback.core.OutputStreamAppender; //导入依赖的package包/类
@Override
public void setVerboseMode(boolean on) {
PatternLayoutEncoder patternLayoutEncoder = new PatternLayoutEncoder();
patternLayoutEncoder.setPattern("[%d{HH:mm:ss.SSS}] [%highlight(%level)] %msg%n");
patternLayoutEncoder.setContext(loggerContext);
patternLayoutEncoder.start();
Appender<ILoggingEvent> consoleAppender = new ConsoleAppender();
((OutputStreamAppender) consoleAppender).setEncoder(patternLayoutEncoder);
consoleAppender.setContext(loggerContext);
consoleAppender.start();
loggerContext.getLogger("com.paypal.butterfly.cli").detachAppender("CONSOLE");
loggerContext.getLogger("ROOT").addAppender(consoleAppender);
}
示例9: setBuffered
import ch.qos.logback.core.OutputStreamAppender; //导入依赖的package包/类
/**
* Turns ImmediateFlush off or on (!buffered) for all encoders descending from
* LayoutWrappingEncoder for appenders descending from OutputStreamAppender
* except ConsoleAppender. The purpose is to turn on or off buffering/flushing
* for all file logging appenders.
*
* Must be called after {@link #loadFile()}.
*
* @param buffered whether or not file logging should be buffered or flush immediately
*/
public static synchronized void setBuffered(boolean buffered) {
if (loggerContext == null) {
LOGGER.error("Unknown loggerContext, aborting buffered logging. Make sure that loadFile() has been called first.");
return;
}
// Build iterator
Iterators<Appender<ILoggingEvent>> iterators = new Iterators<>();
// Add CacheLogger or rootLogger appenders depending on whether CacheLogger is active.
if (CacheLogger.isActive()) {
iterators.addIterator(CacheLogger.iteratorForAppenders());
} else {
iterators.addIterator(rootLogger.iteratorForAppenders());
}
// If syslog is active there probably are detached appenders there as well
if (!syslogDetachedAppenders.isEmpty()) {
iterators.addList(syslogDetachedAppenders);
}
// Iterate
Iterator<Appender<ILoggingEvent>> it = iterators.combinedIterator();
while (it.hasNext()) {
Appender<ILoggingEvent> appender = it.next();
if (appender instanceof OutputStreamAppender && !(appender instanceof ConsoleAppender<?>)) {
// Appender has ImmediateFlush property
((OutputStreamAppender<ILoggingEvent>) appender).setImmediateFlush(!buffered);
}
}
LOGGER.info("Buffered logging turned {}", buffered ? "ON" : "OFF");
}
示例10: 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;
}
示例11: test
import ch.qos.logback.core.OutputStreamAppender; //导入依赖的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);
}
示例12: getJson
import ch.qos.logback.core.OutputStreamAppender; //导入依赖的package包/类
private Map<String, Object> getJson() throws IOException {
OutputStreamAppender<ILoggingEvent> appender = (OutputStreamAppender<ILoggingEvent>) testLogger.getAppender("loggingEventCompositeJsonEncoderAppender");
LoggingEventCompositeJsonEncoder encoder = (LoggingEventCompositeJsonEncoder) appender.getEncoder();
String encodedValue = new String(encoder.encode(listAppender.list.get(0)), "UTF-8");
return jsonFactory.createParser(encodedValue).readValueAs(new TypeReference<Map<String, Object>>() {});
}
示例13: getEncoding
import ch.qos.logback.core.OutputStreamAppender; //导入依赖的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;
}
示例14: buildAppender
import ch.qos.logback.core.OutputStreamAppender; //导入依赖的package包/类
private <T extends OutputStreamAppender<ILoggingEvent>> T buildAppender(T appender, AppenderType type, EncoderBase<ILoggingEvent> encoder, boolean start) {
this.buildAppender(appender, type, false).setEncoder(encoder);
if (start) {
appender.start();
}
return appender;
}
示例15: activateLogging
import ch.qos.logback.core.OutputStreamAppender; //导入依赖的package包/类
static void activateLogging(OutputStreamAppender<ILoggingEvent> appender) {
PatternLayoutEncoder ple = new PatternLayoutEncoder();
ple.setPattern("%date %level [%thread] %logger{10} [%file:%line] %msg%n");
ple.setContext(getContext());
ple.start();
appender.setContext(getContext());
appender.setEncoder(ple);
appender.start();
// add appender to any Logger (here is root)
ch.qos.logback.classic.Logger rootLogger = getRootLogger();
rootLogger.addAppender(appender);
}