String outputAppender = cl.getOptionValue("output", "console");
appender = loggerContext.getLogger(Logger.ROOT_LOGGER_NAME).getAppender(outputAppender);
}
ChronicleTools.warmup();
Chronicle chronicle = new IndexedChronicle(cl.getOptionValue("path"), ChronicleConfig.DEFAULT);
ExcerptTailer ex = chronicle.createTailer();
Level level = Level.valueOf(cl.getOptionValue("level", "TRACE"));
if (cl.hasOption("head")) {
int lines = Integer.parseInt(cl.getOptionValue("head", "10"));
for (int i = 0; i < lines; i++) {
LoggingEvent evt = readLoggingEvent(ex, loggerContext);
if (evt.getLevel().isGreaterOrEqual(level)) {
writeEvent(evt, appender);
}
}
} else if (cl.hasOption("tail")) {
int lines = Integer.parseInt(cl.getOptionValue("tail", "10"));
Queue<LoggingEvent> tail = new LinkedBlockingQueue<LoggingEvent>(lines);
while (ex.nextIndex()) {
LoggingEvent evt = readLoggingEvent(ex, loggerContext);
if (!tail.offer(evt)) {
tail.poll();
tail.add(evt);
}
}
LoggingEvent evt;
while (null != (evt = tail.poll())) {
if (evt.getLevel().isGreaterOrEqual(level)) {
writeEvent(evt, appender);
}
}
} else if (cl.hasOption("search")) {
String regex = cl.getOptionValue("search");
Pattern regexPatt = Pattern.compile(regex);
while (ex.nextIndex()) {
LoggingEvent evt = readLoggingEvent(ex, loggerContext);
if (null != evt && evt.getLevel().isGreaterOrEqual(level)) {
if (regexPatt.matcher(evt.getFormattedMessage()).matches()) {
writeEvent(evt, appender);
}
}
}
}
loggerContext.stop();
chronicle.close();
}