use of org.apache.logging.log4j.core.appender.MemoryMappedFileAppender in project cas by apereo.
the class LoggingOutputSocketMessagingController method registerLogFileTailThreads.
private void registerLogFileTailThreads() throws IOException {
final Collection<String> outputFileNames = new HashSet<>();
final Collection<Appender> loggerAppenders = this.loggerContext.getConfiguration().getAppenders().values();
loggerAppenders.forEach(appender -> {
if (appender instanceof FileAppender) {
outputFileNames.add(((FileAppender) appender).getFileName());
} else if (appender instanceof RandomAccessFileAppender) {
outputFileNames.add(((RandomAccessFileAppender) appender).getFileName());
} else if (appender instanceof RollingFileAppender) {
outputFileNames.add(((RollingFileAppender) appender).getFileName());
} else if (appender instanceof MemoryMappedFileAppender) {
outputFileNames.add(((MemoryMappedFileAppender) appender).getFileName());
} else if (appender instanceof RollingRandomAccessFileAppender) {
outputFileNames.add(((RollingRandomAccessFileAppender) appender).getFileName());
}
});
outputFileNames.forEach(s -> {
final Tailer t = new Tailer(new File(s), new LogTailerListener(), 100, false, true);
final Thread thread = new Thread(t);
thread.setPriority(Thread.MIN_PRIORITY);
thread.setName(s);
thread.start();
});
}
use of org.apache.logging.log4j.core.appender.MemoryMappedFileAppender in project cas by apereo.
the class LoggingOutputTailingService method registerLogFileTailersForExecution.
private void registerLogFileTailersForExecution(final LoggerContext loggerContext) {
final Collection<String> outputFileNames = new HashSet<>();
final Collection<Appender> loggerAppenders = loggerContext.getConfiguration().getAppenders().values();
loggerAppenders.forEach(appender -> {
if (appender instanceof FileAppender) {
outputFileNames.add(FileAppender.class.cast(appender).getFileName());
} else if (appender instanceof RandomAccessFileAppender) {
outputFileNames.add(RandomAccessFileAppender.class.cast(appender).getFileName());
} else if (appender instanceof RollingFileAppender) {
outputFileNames.add(RollingFileAppender.class.cast(appender).getFileName());
} else if (appender instanceof MemoryMappedFileAppender) {
outputFileNames.add(MemoryMappedFileAppender.class.cast(appender).getFileName());
} else if (appender instanceof RollingRandomAccessFileAppender) {
outputFileNames.add(RollingRandomAccessFileAppender.class.cast(appender).getFileName());
}
});
outputFileNames.forEach(f -> {
final Tailer t = new Tailer(new File(f), this, 100L, false, true);
this.tailers.add(t);
this.taskExecutor.execute(t);
});
}
use of org.apache.logging.log4j.core.appender.MemoryMappedFileAppender in project cas by apereo.
the class LoggingConfigurationEndpoint method configuration.
/**
* Configuration map.
*
* @return the map
*/
@ReadOperation
@Operation(summary = "Get logging configuration report")
public Map<String, Object> configuration() {
val configuredLoggers = new HashSet<>();
getLoggerConfigurations().forEach(config -> {
val loggerMap = new HashMap<String, Object>();
loggerMap.put("name", StringUtils.defaultIfBlank(config.getName(), LOGGER_NAME_ROOT));
loggerMap.put("state", config.getState());
if (config.getPropertyList() != null) {
loggerMap.put("properties", config.getPropertyList());
}
loggerMap.put("additive", config.isAdditive());
loggerMap.put("level", config.getLevel().name());
val appenders = new HashSet<>();
config.getAppenders().keySet().stream().map(key -> config.getAppenders().get(key)).forEach(appender -> {
val builder = new ToStringBuilder(this, ToStringStyle.JSON_STYLE);
builder.append("name", appender.getName());
builder.append("state", appender.getState());
builder.append("layoutFormat", appender.getLayout().getContentFormat());
builder.append("layoutContentType", appender.getLayout().getContentType());
if (appender instanceof FileAppender) {
builder.append(FILE_PARAM, ((FileAppender) appender).getFileName());
builder.append(FILE_PATTERN_PARAM, "(none)");
}
if (appender instanceof RandomAccessFileAppender) {
builder.append(FILE_PARAM, ((RandomAccessFileAppender) appender).getFileName());
builder.append(FILE_PATTERN_PARAM, "(none)");
}
if (appender instanceof RollingFileAppender) {
builder.append(FILE_PARAM, ((RollingFileAppender) appender).getFileName());
builder.append(FILE_PATTERN_PARAM, ((RollingFileAppender) appender).getFilePattern());
}
if (appender instanceof MemoryMappedFileAppender) {
builder.append(FILE_PARAM, ((MemoryMappedFileAppender) appender).getFileName());
builder.append(FILE_PATTERN_PARAM, "(none)");
}
if (appender instanceof RollingRandomAccessFileAppender) {
builder.append(FILE_PARAM, ((RollingRandomAccessFileAppender) appender).getFileName());
builder.append(FILE_PATTERN_PARAM, ((RollingRandomAccessFileAppender) appender).getFilePattern());
}
appenders.add(builder.build());
});
loggerMap.put("appenders", appenders);
configuredLoggers.add(loggerMap);
});
val responseMap = new HashMap<String, Object>();
responseMap.put("loggers", configuredLoggers);
val loggers = getActiveLoggersInFactory();
responseMap.put("activeLoggers", loggers.values());
return responseMap;
}
use of org.apache.logging.log4j.core.appender.MemoryMappedFileAppender in project cas by apereo.
the class LoggingConfigController method getConfiguration.
/**
* Gets configuration as JSON.
* Depends on the log4j core API.
*
* @param request the request
* @param response the response
* @return the configuration
* @throws Exception the exception
*/
@GetMapping(value = "/getConfiguration")
@ResponseBody
public Map<String, Object> getConfiguration(final HttpServletRequest request, final HttpServletResponse response) throws Exception {
ensureEndpointAccessIsAuthorized(request, response);
final Collection<Map<String, Object>> configuredLoggers = new HashSet<>();
getLoggerConfigurations().forEach(config -> {
final Map<String, Object> loggerMap = new HashMap<>();
loggerMap.put("name", StringUtils.defaultIfBlank(config.getName(), LOGGER_NAME_ROOT));
loggerMap.put("state", config.getState());
if (config.getProperties() != null) {
loggerMap.put("properties", config.getProperties());
}
loggerMap.put("additive", config.isAdditive());
loggerMap.put("level", config.getLevel().name());
final Collection<String> appenders = new HashSet<>();
config.getAppenders().keySet().stream().map(key -> config.getAppenders().get(key)).forEach(appender -> {
final ToStringBuilder builder = new ToStringBuilder(this, ToStringStyle.JSON_STYLE);
builder.append("name", appender.getName());
builder.append("state", appender.getState());
builder.append("layoutFormat", appender.getLayout().getContentFormat());
builder.append("layoutContentType", appender.getLayout().getContentType());
if (appender instanceof FileAppender) {
builder.append(FILE_PARAM, ((FileAppender) appender).getFileName());
builder.append(FILE_PATTERN_PARAM, "(none)");
}
if (appender instanceof RandomAccessFileAppender) {
builder.append(FILE_PARAM, ((RandomAccessFileAppender) appender).getFileName());
builder.append(FILE_PATTERN_PARAM, "(none)");
}
if (appender instanceof RollingFileAppender) {
builder.append(FILE_PARAM, ((RollingFileAppender) appender).getFileName());
builder.append(FILE_PATTERN_PARAM, ((RollingFileAppender) appender).getFilePattern());
}
if (appender instanceof MemoryMappedFileAppender) {
builder.append(FILE_PARAM, ((MemoryMappedFileAppender) appender).getFileName());
builder.append(FILE_PATTERN_PARAM, "(none)");
}
if (appender instanceof RollingRandomAccessFileAppender) {
builder.append(FILE_PARAM, ((RollingRandomAccessFileAppender) appender).getFileName());
builder.append(FILE_PATTERN_PARAM, ((RollingRandomAccessFileAppender) appender).getFilePattern());
}
appenders.add(builder.build());
});
loggerMap.put("appenders", appenders);
configuredLoggers.add(loggerMap);
});
final Map<String, Object> responseMap = new HashMap<>();
responseMap.put("loggers", configuredLoggers);
return responseMap;
}
Aggregations