本文整理汇总了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());
}
示例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());
}
示例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;
}
示例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());
}
示例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();
}
示例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));
}
}
示例7: deactivate
import ch.qos.logback.core.FileAppender; //导入方法依赖的package包/类
public void deactivate() {
for(FileAppender<ILoggingEvent> appender : appenders.values()) {
appender.stop();
}
appenders.clear();
}
示例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;
}
示例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;
}
示例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();
}
示例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;
}