Search in sources :

Example 6 with LogControlException

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);
    }
}
Also used : ExportDisplay(com.haulmont.cuba.gui.export.ExportDisplay) LogControlException(com.haulmont.cuba.core.sys.logging.LogControlException) JmxInstance(com.haulmont.cuba.core.entity.JmxInstance) LogDataProvider(com.haulmont.cuba.web.export.LogDataProvider)

Example 7 with LogControlException

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, " ", "&nbsp;");
        // 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);
}
Also used : CubaScrollBoxLayout(com.haulmont.cuba.web.toolkit.ui.CubaScrollBoxLayout) BufferedReader(java.io.BufferedReader) StringReader(java.io.StringReader) LogControlException(com.haulmont.cuba.core.sys.logging.LogControlException) Level(ch.qos.logback.classic.Level) JmxControlException(com.haulmont.cuba.web.jmx.JmxControlException) IOException(java.io.IOException)

Aggregations

LogControlException (com.haulmont.cuba.core.sys.logging.LogControlException)7 Level (ch.qos.logback.classic.Level)5 JmxControlException (com.haulmont.cuba.web.jmx.JmxControlException)5 IOException (java.io.IOException)2 ParamsMap (com.haulmont.bali.util.ParamsMap)1 JmxInstance (com.haulmont.cuba.core.entity.JmxInstance)1 LogFileNotFoundException (com.haulmont.cuba.core.sys.logging.LogFileNotFoundException)1 ExportDisplay (com.haulmont.cuba.gui.export.ExportDisplay)1 LogDataProvider (com.haulmont.cuba.web.export.LogDataProvider)1 CubaScrollBoxLayout (com.haulmont.cuba.web.toolkit.ui.CubaScrollBoxLayout)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 RandomAccessFile (java.io.RandomAccessFile)1 StringReader (java.io.StringReader)1