use of com.haulmont.cuba.core.sys.logging.LogControlException in project cuba by cuba-platform.
the class ServerLogWindow method downloadLog.
public void downloadLog() {
final String fileName = logFileNameField.getValue();
if (fileName != null) {
try {
final JmxInstance selectedConnection = getSelectedConnection();
// check if we have many suitable JmxControlBean instances
// show dialog with context select and size options if needed
List<String> availableContexts = jmxRemoteLoggingAPI.getAvailableContexts(selectedConnection);
long size = jmxRemoteLoggingAPI.getLogFileSize(selectedConnection, fileName);
if (size <= LogArchiver.LOG_TAIL_FOR_PACKING_SIZE && availableContexts.size() == 1) {
LogDataProvider dataProvider = new LogDataProvider(selectedConnection, fileName, availableContexts.get(0), false);
dataProvider.obtainUrl();
ExportDisplay exportDisplay = AppConfig.createExportDisplay(this);
exportDisplay.show(dataProvider, fileName + ".zip");
} else {
openWindow("serverLogDownloadOptionsDialog", OpenType.DIALOG, ParamsMap.of("logFileName", fileName, "connection", selectedConnection, "logFileSize", size, "remoteContextList", availableContexts));
}
} catch (RuntimeException | LogControlException e) {
showNotification(getMessage("exception.logControl"), NotificationType.ERROR);
log.error("Error downloading log", e);
}
} else {
showNotification(getMessage("log.notSelected"), NotificationType.HUMANIZED);
}
}
use of com.haulmont.cuba.core.sys.logging.LogControlException in project cuba by cuba-platform.
the class ServerLogWindow method updateLogTail.
public void updateLogTail(boolean isTimedEvent) {
if (logFileNameField.getValue() != null) {
String logFileName = logFileNameField.getValue();
String value;
try {
value = jmxRemoteLoggingAPI.getTail(getSelectedConnection(), logFileName);
} catch (LogControlException | JmxControlException e) {
log.error("Error loading log tail", e);
if (!isTimedEvent)
showNotification(getMessage("exception.logControl"), NotificationType.ERROR);
return;
}
// transform to XHTML
value = StringEscapeUtils.escapeHtml(value);
value = StringUtils.replace(value, " ", " ");
// highlight log
StringBuilder coloredLog = new StringBuilder();
BufferedReader reader = new BufferedReader(new StringReader(value));
try {
List<String> logLevels = new LinkedList<>();
// highlight tomcat catalina levels
logLevels.add("WARNING");
logLevels.add("SEVERE");
// highlight log4j levels
for (Level level : LoggingHelper.getLevels()) {
logLevels.add(level.toString());
}
String line;
while ((line = reader.readLine()) != null) {
// replace one level per line
for (String level : logLevels) {
String highlightedLine = highlightLevel(line, level);
if (!Objects.equals(highlightedLine, line)) {
line = highlightedLine;
break;
}
}
coloredLog.append(line).append("<br/>");
}
} catch (IOException e) {
log.warn("Error updating log tail", e);
return;
}
logTailLabel.setValue(coloredLog.toString());
} else {
showNotification(getMessage("log.notSelected"), NotificationType.HUMANIZED);
}
logContainer.unwrap(CubaScrollBoxLayout.class).setScrollTop(30000);
}
Aggregations