use of ch.qos.logback.core.Appender in project ddf by codice.
the class ApplicationServiceImplTest method testGetAllFeaturesException.
/**
* Tests the {@link ApplicationServiceImpl#getAllFeatures()} method
* for the case where an exception is thrown by the featuresService
*
* @throws Exception
*/
// TODO RAP 29 Aug 16: DDF-2443 - Fix test to not depend on specific log output
@Test
public void testGetAllFeaturesException() throws Exception {
ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
final Appender mockAppender = mock(Appender.class);
when(mockAppender.getName()).thenReturn("MOCK");
root.addAppender(mockAppender);
Set<Repository> activeRepos = new HashSet<Repository>(Arrays.asList(mainFeatureRepo, noMainFeatureRepo1, noMainFeatureRepo2));
FeaturesService featuresService = createMockFeaturesService(activeRepos, null, null);
when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
ApplicationService appService = createPermittedApplicationServiceImpl();
doThrow(new NullPointerException()).when(featuresService).listFeatures();
appService.getAllFeatures();
verify(mockAppender).doAppend(argThat(new ArgumentMatcher() {
@Override
public boolean matches(final Object argument) {
return ((LoggingEvent) argument).getFormattedMessage().contains(FEATURE_FAIL_STRING);
}
}));
}
use of ch.qos.logback.core.Appender in project ddf by codice.
the class ApplicationServiceImplTest method testFindApplicationFeaturesGetRepoFeatException.
/**
* Tests the {@link ApplicationServiceImpl#findApplicationFeatures(String)} method
* for the case where an exception is thrown in getRepositoryFeatures
*
* @throws Exception
*/
// TODO RAP 29 Aug 16: DDF-2443 - Fix test to not depend on specific log output
@Test
public void testFindApplicationFeaturesGetRepoFeatException() throws Exception {
ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
final Appender mockAppender = mock(Appender.class);
when(mockAppender.getName()).thenReturn("MOCK");
root.addAppender(mockAppender);
Set<Repository> activeRepos = new HashSet<Repository>(Arrays.asList(mainFeatureRepo, noMainFeatureRepo1, noMainFeatureRepo2));
FeaturesService featuresService = createMockFeaturesService(activeRepos, null, null);
when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
ApplicationService appService = new ApplicationServiceImpl(bundleStateServices) {
@Override
protected BundleContext getContext() {
return bundleContext;
}
};
Repository testRepo = mock(Repository.class);
Repository[] repoList = { testRepo };
when(featuresService.listRepositories()).thenReturn(repoList);
when(testRepo.getName()).thenReturn(TEST_APP_NAME);
doThrow(new Exception()).when(testRepo).getFeatures();
appService.findApplicationFeatures(TEST_APP_NAME);
verify(mockAppender).doAppend(argThat(new ArgumentMatcher() {
@Override
public boolean matches(final Object argument) {
return ((LoggingEvent) argument).getFormattedMessage().contains(NO_REPO_FEATURES);
}
}));
}
use of ch.qos.logback.core.Appender in project ha-bridge by bwssytems.
the class LoggingUtil method getLogFileInfos.
/**
* Get the logfile information for the roor logger.
*
* @return List of LogFileInfo obejcts
*/
public static List<LogFileInfo> getLogFileInfos() {
final LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
final List<LogFileInfo> logFileInfos = new ArrayList<LogFileInfo>();
final Logger logger = lc.getLogger(Logger.ROOT_LOGGER_NAME);
final Iterator<Appender<ILoggingEvent>> it = logger.iteratorForAppenders();
while (it.hasNext()) {
final Appender<ILoggingEvent> appender = it.next();
if (appender instanceof FileAppender) {
final FileAppender<ILoggingEvent> fileAppender = (FileAppender<ILoggingEvent>) appender;
final File logFile = new File(fileAppender.getFile());
final LogFileInfo logFileInfo = new LogFileInfo();
logFileInfo.setFileName(logFile.getName());
logFileInfo.setFileLastChanged(new Date(logFile.lastModified()));
logFileInfo.setFileSize(logFile.length());
logFileInfos.add(logFileInfo);
}
}
return logFileInfos;
}
use of ch.qos.logback.core.Appender in project ha-bridge by bwssytems.
the class LoggingUtil method getLogFile.
/**
* Get the log file.
*
* @param logFileName The name of the log file
* @return The actual file
*/
public static File getLogFile(final String logFileName) {
if (logFileName == null) {
throw new IllegalArgumentException("logFileName cannot be null.");
}
final LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
final Logger logger = lc.getLogger(Logger.ROOT_LOGGER_NAME);
final Iterator<Appender<ILoggingEvent>> it = logger.iteratorForAppenders();
while (it.hasNext()) {
final Appender<ILoggingEvent> appender = it.next();
if (appender instanceof FileAppender) {
final FileAppender<ILoggingEvent> fileAppender = (FileAppender<ILoggingEvent>) appender;
final File logFile = new File(fileAppender.getFile());
if (logFile.getName().equalsIgnoreCase(logFileName)) {
return logFile;
}
}
}
return null;
}
use of ch.qos.logback.core.Appender in project sling by apache.
the class LogTailerWebConsolePlugin method getOptions.
private String getOptions() {
Set<String> logFiles = new HashSet<String>();
LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
for (ch.qos.logback.classic.Logger logger : context.getLoggerList()) {
for (Iterator<Appender<ILoggingEvent>> index = logger.iteratorForAppenders(); index.hasNext(); ) {
Appender<ILoggingEvent> appender = index.next();
if (appender instanceof FileAppender) {
FileAppender fileAppender = (FileAppender) appender;
String logfilePath = fileAppender.getFile();
logFiles.add(logfilePath);
}
}
}
String logFilesHtml = "<option value=\"\"> - Select file - </option>";
for (String logFile : logFiles) {
File file = new File(logFile);
logFilesHtml += "<option value=\"" + getKey(file) + "\">" + file.getName() + "</option>";
}
return logFilesHtml;
}
Aggregations