當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。