当前位置: 首页>>代码示例>>Java>>正文


Java OutputStreamAppender.start方法代码示例

本文整理汇总了Java中ch.qos.logback.core.OutputStreamAppender.start方法的典型用法代码示例。如果您正苦于以下问题:Java OutputStreamAppender.start方法的具体用法?Java OutputStreamAppender.start怎么用?Java OutputStreamAppender.start使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ch.qos.logback.core.OutputStreamAppender的用法示例。


在下文中一共展示了OutputStreamAppender.start方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
 
开发者ID:spinscale,项目名称:maxcube-java,代码行数:26,代码来源:Cli.java

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

示例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;
}
 
开发者ID:krestovsky,项目名称:log4ju,代码行数:26,代码来源:LogTester.java

示例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;
}
 
开发者ID:headwirecom,项目名称:aemdc,代码行数:40,代码来源:MainApp.java

示例5: 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);
}
 
开发者ID:termsuite,项目名称:termsuite-core,代码行数:14,代码来源:LogbackUtils.java

示例6: configureLogging

import ch.qos.logback.core.OutputStreamAppender; //导入方法依赖的package包/类
private static void configureLogging(File logFile, Level level) {
    LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
    OutputStreamAppender<ILoggingEvent> appender;
    if (logFile == null) {
        appender = configureConsoleLogging(loggerContext);
    } else {
        appender = configureFileLogging(logFile, loggerContext);
    }
    System.out.println("Logging: The log level is set to " + level);
    PatternLayoutEncoder patternLayoutEncoder = new PatternLayoutEncoder();
    patternLayoutEncoder.setPattern(LogDescription.LOG_PATTERN);
    patternLayoutEncoder.setContext(loggerContext);
    patternLayoutEncoder.start();
    appender.setEncoder(patternLayoutEncoder);
    appender.start();
    ch.qos.logback.classic.Logger rootLogger = loggerContext.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME);
    loggerContext.stop();
    rootLogger.detachAndStopAllAppenders();
    rootLogger.addAppender(appender);
    rootLogger.setLevel(level);
    SLF4JBridgeHandler.removeHandlersForRootLogger();
    SLF4JBridgeHandler.install();
    LevelChangePropagator levelChangePropagator = new LevelChangePropagator();
    levelChangePropagator.setResetJUL(true);
    levelChangePropagator.setContext(loggerContext);
    levelChangePropagator.start();
    loggerContext.addListener(levelChangePropagator);
    loggerContext.start();
}
 
开发者ID:documents4j,项目名称:documents4j,代码行数:30,代码来源:StandaloneClient.java

示例7: configure

import ch.qos.logback.core.OutputStreamAppender; //导入方法依赖的package包/类
public Handler configure() {

        final Logger logger = (Logger) LoggerFactory.getLogger("http.request");
        logger.setAdditive(false);

        final LoggerContext context = logger.getLoggerContext();

        final AppenderAttachableImpl<ILoggingEvent> appenders = new AppenderAttachableImpl<ILoggingEvent>();

        final RequestLogLayout layout = new RequestLogLayout();
        layout.start();

        for (OutputStreamAppender<ILoggingEvent> appender : LogbackFactory.buildAppenders(config.getRequestLogConfiguration(),
                context)) {
            appender.stop();
            appender.setLayout(layout);
            appender.start();
            appenders.addAppender(appender);
        }

        final RequestLogHandler handler = new RequestLogHandler();
        handler.setRequestLog(new AsyncRequestLog(Clock.defaultClock(),
                appenders,
                config.getRequestLogConfiguration().getTimeZone(),
                config.getRequestLogConfiguration().getCookies()));

        return handler;

    }
 
开发者ID:wotifgroup,项目名称:grails-lightweight-deploy,代码行数:30,代码来源:RequestLoggingFactory.java

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

示例9: 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]") );
   
}
 
开发者ID:danidemi,项目名称:jlubricant,代码行数:59,代码来源:DenyDuplicationsFilterIntegrationTest.java


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