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


Java FileAppender.stop方法代码示例

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


在下文中一共展示了FileAppender.stop方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: smoke

import ch.qos.logback.core.FileAppender; //导入方法依赖的package包/类
@Test
public void smoke() {
  String filename = CoreTestConstants.OUTPUT_DIR_PREFIX + "/fat-smoke.log";

  FileAppender<Object> appender = new FileAppender<Object>();
  appender.setEncoder(new DummyEncoder<Object>());
  appender.setAppend(false);
  appender.setFile(filename);
  appender.setName("smoke");
  appender.setContext(context);
  appender.start();
  appender.doAppend(new Object());
  appender.stop();

  File file = new File(filename);
  assertTrue(file.exists());
  assertTrue("failed to delete " + file.getAbsolutePath(), file.delete());
}
 
开发者ID:cscfa,项目名称:bartleby,代码行数:19,代码来源:FileAppenderTest.java

示例2: testCreateParentFolders

import ch.qos.logback.core.FileAppender; //导入方法依赖的package包/类
@Test
public void testCreateParentFolders() {
  String filename = CoreTestConstants.OUTPUT_DIR_PREFIX + "/fat-testCreateParentFolders-" + diff
      + "/testCreateParentFolders.txt";
  File file = new File(filename);
  assertFalse(file.getParentFile().exists());
  assertFalse(file.exists());

  FileAppender<Object> appender = new FileAppender<Object>();
  appender.setEncoder(new DummyEncoder<Object>());
  appender.setAppend(false);
  appender.setFile(filename);
  appender.setName("testCreateParentFolders");
  appender.setContext(context);
  appender.start();
  appender.doAppend(new Object());
  appender.stop();
  assertTrue(file.getParentFile().exists());
  assertTrue(file.exists());

  // cleanup
  assertTrue("failed to delete " + file.getAbsolutePath(), file.delete());
  File parent = file.getParentFile();
  assertTrue("failed to delete " + parent.getAbsolutePath(), parent.delete());
}
 
开发者ID:cscfa,项目名称:bartleby,代码行数:26,代码来源:FileAppenderTest.java

示例3: getTaskLogHome

import ch.qos.logback.core.FileAppender; //导入方法依赖的package包/类
/**
 * Get the home (absolute path) of the task logs on disk
 *
 * @return the task log home, null if it couldn't be found (usually due to missing appender in logback.xml)
 */
@Nullable
public static String getTaskLogHome() {
  LoggerContext loggerContext = (LoggerContext) StaticLoggerBinder.getSingleton().getLoggerFactory();

  Appender appender = loggerContext.getLogger(ROOT_LOGGER_NAME).getAppender("tasklogfile");
  if (!(appender instanceof SiftingAppender)) {
    // We are forgiving if the task log appender does not exist. It could be that a user had a customized logback.xml
    // as of 3.4.1 when task logging was introduced. We don't want to block application start in this scenario.
    log.error("Could not find a Logback SiftingAppender named 'tasklogfile' in the logback configuration. " +
       "Please check that the 'tasklogfile' appender exists in logback.xml");
    return null;
  }
  SiftingAppender siftingAppender = (SiftingAppender) appender;

  // this will create a new appender which ultimately creates a temp.log within the tasks log folder
  FileAppender tempFileAppender = (FileAppender) siftingAppender.getAppenderTracker().getOrCreate("temp", 0L);

  // Note that at full execution speed the temp.log may not actually exist yet, but we don't actually need it to
  File file = new File(tempFileAppender.getFile());

  String taskLogsFolder = file.getParent();

  // no need to keep the temp.log file around
  tempFileAppender.stop(); // stop the appender to release file lock (windows)
  FileUtils.deleteQuietly(file);

  return taskLogsFolder;
}
 
开发者ID:sonatype,项目名称:nexus-public,代码行数:34,代码来源:TaskLogHome.java

示例4: testPrudentModeLogicalImplications

import ch.qos.logback.core.FileAppender; //导入方法依赖的package包/类
@Test
public void testPrudentModeLogicalImplications() {
  String filename = CoreTestConstants.OUTPUT_DIR_PREFIX + diff + "fat-testPrudentModeLogicalImplications.txt";
  File file = new File(filename);
  FileAppender<Object> appender = new FileAppender<Object>();
  appender.setEncoder(new DummyEncoder<Object>());
  appender.setFile(filename);
  appender.setName("testPrudentModeLogicalImplications");
  appender.setContext(context);

  appender.setAppend(false);
  appender.setPrudent(true);
  appender.start();

  assertTrue(appender.isAppend());

  StatusManager sm = context.getStatusManager();
  //StatusPrinter.print(context);
  StatusChecker statusChecker = new StatusChecker(context);
  assertEquals(Status.WARN, statusChecker.getHighestLevel(0));
  List<Status> statusList = sm.getCopyOfStatusList();
  assertTrue("Expecting status list size to be 2 or larger, but was "
      + statusList.size(), statusList.size() >= 2);
  String msg1 = statusList.get(1).getMessage();

  assertTrue("Got message [" + msg1 + "]", msg1
      .startsWith("Setting \"Append\" property"));
  
  appender.doAppend(new Object());
  appender.stop();
  assertTrue(file.exists());
  assertTrue("failed to delete " + file.getAbsolutePath(), file.delete());
}
 
开发者ID:cscfa,项目名称:bartleby,代码行数:34,代码来源:FileAppenderTest.java

示例5: configureAppender

import ch.qos.logback.core.FileAppender; //导入方法依赖的package包/类
private static void configureAppender(String filePath, FileAppender appender) {
    if (appender.isStarted()) {
        appender.stop();
    }
    appender.setFile(filePath.replace(".log", ".auditLogFile.log"));
    appender.start();
}
 
开发者ID:ezbake,项目名称:ezbake-common-java,代码行数:8,代码来源:AuditLoggerConfigurator.java

示例6: run

import ch.qos.logback.core.FileAppender; //导入方法依赖的package包/类
@Override
public void run(T configuration, Environment environment) throws Exception {
    final LogstashLogbackEncoderConfiguration lleConfig = getConfiguration(configuration);
    if (lleConfig.isEnabled()) {
        final Logger root = (Logger) LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
        final FileAppender<ILoggingEvent> jsonFileAppender = LogbackFactory.buildFileAppender(lleConfig,
                root.getLoggerContext(), lleConfig.getLogFormat());
        final LogstashEncoder logstashEncoder = new LogstashEncoder();
        logstashEncoder.setIncludeCallerInfo(lleConfig.isIncludeCallerInfo());
        jsonFileAppender.stop();
        jsonFileAppender.setEncoder(logstashEncoder);
        jsonFileAppender.start();
        root.addAppender(AsyncAppender.wrap(jsonFileAppender));
    }
}
 
开发者ID:looztra,项目名称:logstash-logback-encoder-bundle,代码行数:16,代码来源:LogstashLogbackEncoderBundle.java

示例7: deactivate

import ch.qos.logback.core.FileAppender; //导入方法依赖的package包/类
public void deactivate() {
	for(FileAppender<ILoggingEvent> appender : appenders.values()) {
		appender.stop();
	}
	appenders.clear();
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:7,代码来源:LoggingPersistenceService.java

示例8: buildFileAppender

import ch.qos.logback.core.FileAppender; //导入方法依赖的package包/类
public static FileAppender<ILoggingEvent> buildFileAppender(LoggingConfiguration.FileConfiguration file,
                                                            LoggerContext context,
                                                            String logFormat) {
    final LogFormatter formatter = new LogFormatter(context, file.getTimeZone());

    if (logFormat != null) {
        formatter.setPattern(logFormat);
    }
    formatter.start();

    final FileAppender<ILoggingEvent> appender =
            file.isArchive() ? new RollingFileAppender<ILoggingEvent>() :
                    new FileAppender<ILoggingEvent>();

    appender.setAppend(true);
    appender.setContext(context);
    appender.setLayout(formatter);
    appender.setFile(file.getCurrentLogFilename());
    appender.setPrudent(false);

    addThresholdFilter(appender, file.getThreshold());

    if (file.isArchive()) {

        final DefaultTimeBasedFileNamingAndTriggeringPolicy<ILoggingEvent> triggeringPolicy =
                new DefaultTimeBasedFileNamingAndTriggeringPolicy<ILoggingEvent>();
        triggeringPolicy.setContext(context);

        final TimeBasedRollingPolicy<ILoggingEvent> rollingPolicy = new TimeBasedRollingPolicy<ILoggingEvent>();
        rollingPolicy.setContext(context);
        rollingPolicy.setFileNamePattern(file.getArchivedLogFilenamePattern());
        rollingPolicy.setTimeBasedFileNamingAndTriggeringPolicy(triggeringPolicy);
        triggeringPolicy.setTimeBasedRollingPolicy(rollingPolicy);
        rollingPolicy.setMaxHistory(file.getArchivedFileCount());

        ((RollingFileAppender<ILoggingEvent>) appender).setRollingPolicy(rollingPolicy);
        ((RollingFileAppender<ILoggingEvent>) appender).setTriggeringPolicy(triggeringPolicy);

        rollingPolicy.setParent(appender);
        rollingPolicy.start();
    }

    appender.stop();
    appender.start();

    return appender;
}
 
开发者ID:bither,项目名称:bither-desktop-java,代码行数:48,代码来源:LogbackFactory.java

示例9: getFileAppender

import ch.qos.logback.core.FileAppender; //导入方法依赖的package包/类
private FileAppender<ILoggingEvent> getFileAppender(final LoggingSettings.LogFile settings,
                                                           final LoggerContext context) {
    final PatternLayout formatter = getPatternLayout(context);
    formatter.setPattern(settings.getLogFormat());
    formatter.start();

    final FileAppender<ILoggingEvent> appender =
        settings.isArchive() ? new RollingFileAppender<ILoggingEvent>() :
                               new FileAppender<ILoggingEvent>();

    appender.setAppend(true);
    appender.setContext(context);
    appender.setLayout(formatter);
    appender.setFile(settings.getCurrentLogFilename());
    appender.setPrudent(false);

    addThresholdFilter(appender, settings.getThreshold());

    if (settings.isArchive()) {

        final DefaultTimeBasedFileNamingAndTriggeringPolicy<ILoggingEvent> triggeringPolicy =
                new DefaultTimeBasedFileNamingAndTriggeringPolicy<ILoggingEvent>();
        final TimeBasedRollingPolicy<ILoggingEvent> rollingPolicy = new TimeBasedRollingPolicy<ILoggingEvent>();

        triggeringPolicy.setContext(context);
        triggeringPolicy.setTimeBasedRollingPolicy(rollingPolicy);

        rollingPolicy.setContext(context);
        rollingPolicy.setFileNamePattern(settings.getArchivedLogFilenamePattern());
        rollingPolicy.setTimeBasedFileNamingAndTriggeringPolicy(triggeringPolicy);
        rollingPolicy.setMaxHistory(settings.getArchivedFileCount());

        ((RollingFileAppender<ILoggingEvent>)appender).setRollingPolicy(rollingPolicy);
        ((RollingFileAppender<ILoggingEvent>)appender).setTriggeringPolicy(triggeringPolicy);

        rollingPolicy.setParent(appender);
        rollingPolicy.start();
    }

    appender.stop();
    appender.start();

    return appender;
}
 
开发者ID:Metrink,项目名称:croquet,代码行数:45,代码来源:CroquetLoggingFactory.java

示例10: deactivate

import ch.qos.logback.core.FileAppender; //导入方法依赖的package包/类
public void deactivate(final int reason) {
    for (FileAppender<ILoggingEvent> appender : appenders.values()) {
        appender.stop();
    }
    appenders.clear();
}
 
开发者ID:openhab,项目名称:openhab1-addons,代码行数:7,代码来源:LoggingPersistenceService.java

示例11: buildFileAppender

import ch.qos.logback.core.FileAppender; //导入方法依赖的package包/类
public static FileAppender<ILoggingEvent> buildFileAppender(FileLoggingConfiguration file,
                                                            LoggerContext context) {
    final LogFormatter formatter = new LogFormatter(context, file.getTimeZone());
    for (String format : file.getLogFormat().asSet()) {
        formatter.setPattern(format);
    }
    formatter.start();

    final FileAppender<ILoggingEvent> appender =
            file.isArchive() ? new RollingFileAppender<ILoggingEvent>() :
                    new FileAppender<ILoggingEvent>();

    appender.setAppend(true);
    appender.setContext(context);
    appender.setLayout(formatter);
    appender.setFile(file.getCurrentLogFilename());
    appender.setPrudent(false);

    addThresholdFilter(appender, file.getThreshold());

    if (file.isArchive()) {

        final DefaultTimeBasedFileNamingAndTriggeringPolicy<ILoggingEvent> triggeringPolicy =
                new DefaultTimeBasedFileNamingAndTriggeringPolicy<ILoggingEvent>();
        triggeringPolicy.setContext(context);

        final TimeBasedRollingPolicy<ILoggingEvent> rollingPolicy = new TimeBasedRollingPolicy<ILoggingEvent>();
        rollingPolicy.setContext(context);
        rollingPolicy.setFileNamePattern(file.getArchivedLogFilenamePattern());
        rollingPolicy.setTimeBasedFileNamingAndTriggeringPolicy(
                triggeringPolicy);
        triggeringPolicy.setTimeBasedRollingPolicy(rollingPolicy);
        rollingPolicy.setMaxHistory(file.getArchivedFileCount());

        ((RollingFileAppender<ILoggingEvent>) appender).setRollingPolicy(rollingPolicy);
        ((RollingFileAppender<ILoggingEvent>) appender).setTriggeringPolicy(triggeringPolicy);

        rollingPolicy.setParent(appender);
        rollingPolicy.start();
    }

    appender.stop();
    appender.start();

    return appender;
}
 
开发者ID:wotifgroup,项目名称:grails-lightweight-deploy,代码行数:47,代码来源:LogbackFactory.java


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