use of org.apache.geode.management.internal.cli.util.LogFilter in project geode by apache.
the class SizeExportLogsFunction method estimateLogFileSize.
long estimateLogFileSize(final DistributedMember member, final File logFile, final File statArchive, final Args args) throws IOException {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("SizeExportLogsFunction started for member {}", member);
}
File baseLogFile = null;
File baseStatsFile = null;
if (args.isIncludeLogs() && !logFile.toString().isEmpty()) {
baseLogFile = logFile.getAbsoluteFile();
}
if (args.isIncludeStats() && !statArchive.toString().isEmpty()) {
baseStatsFile = statArchive.getAbsoluteFile();
}
LogFilter logFilter = new LogFilter(args.getLogLevel(), args.isThisLogLevelOnly(), args.getStartTime(), args.getEndTime());
long estimatedSize = new LogExporter(logFilter, baseLogFile, baseStatsFile).estimateFilteredSize();
LOGGER.info("Estimated log file size: " + estimatedSize);
return estimatedSize;
}
use of org.apache.geode.management.internal.cli.util.LogFilter in project geode by apache.
the class ExportLogsFunction method execute.
@Override
public void execute(final FunctionContext context) {
try {
InternalCache cache = GemFireCacheImpl.getInstance();
DistributionConfig config = cache.getInternalDistributedSystem().getConfig();
String memberId = cache.getDistributedSystem().getMemberId();
logger.info("ExportLogsFunction started for member {}", memberId);
Region exportLogsRegion = createOrGetExistingExportLogsRegion(false, cache);
Args args = (Args) context.getArguments();
File baseLogFile = null;
File baseStatsFile = null;
if (args.isIncludeLogs() && !config.getLogFile().toString().isEmpty()) {
baseLogFile = config.getLogFile().getAbsoluteFile();
}
if (args.isIncludeStats() && !config.getStatisticArchiveFile().toString().isEmpty()) {
baseStatsFile = config.getStatisticArchiveFile().getAbsoluteFile();
}
LogFilter logFilter = new LogFilter(args.getLogLevel(), args.isThisLogLevelOnly(), args.getStartTime(), args.getEndTime());
Path exportedZipFile = new LogExporter(logFilter, baseLogFile, baseStatsFile).export();
// nothing to return back
if (exportedZipFile == null) {
context.getResultSender().lastResult(null);
return;
}
logger.info("Streaming zipped file: " + exportedZipFile.toString());
try (FileInputStream inputStream = new FileInputStream(exportedZipFile.toFile())) {
byte[] buffer = new byte[BUFFER_SIZE];
int bytesRead;
while ((bytesRead = inputStream.read(buffer)) > 0) {
if (bytesRead == BUFFER_SIZE) {
exportLogsRegion.put(memberId, buffer);
} else {
exportLogsRegion.put(memberId, Arrays.copyOfRange(buffer, 0, bytesRead));
}
}
}
context.getResultSender().lastResult(null);
} catch (Exception e) {
e.printStackTrace();
logger.error(e);
context.getResultSender().sendException(e);
}
}
Aggregations