Search in sources :

Example 1 with TelemetryLogstashAppender

use of org.terasology.telemetry.logstash.TelemetryLogstashAppender in project Terasology by MovingBlocks.

the class TelemetrySubSystem method addTelemetryLogstashAppender.

private void addTelemetryLogstashAppender(Context rootContext) {
    LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
    TelemetryLogstashAppender telemetryLogstashAppender = new TelemetryLogstashAppender(rootContext);
    lc.getLogger(Logger.ROOT_LOGGER_NAME).addAppender(telemetryLogstashAppender);
    Config config = rootContext.get(Config.class);
    TelemetryConfig telemetryConfig = config.getTelemetryConfig();
    String errorReportingDestination = telemetryConfig.getErrorReportingDestination();
    if (errorReportingDestination == null) {
        errorReportingDestination = TelemetryLogstashAppender.DEFAULT_LOGSTASH_HOST + ":" + TelemetryLogstashAppender.DEFAULT_LOGSTASH_PORT;
        telemetryConfig.setErrorReportingDestination(errorReportingDestination);
    }
    if (telemetryConfig.isErrorReportingEnabled()) {
        telemetryLogstashAppender.addDestination(errorReportingDestination);
        telemetryLogstashAppender.start();
    }
}
Also used : TelemetryLogstashAppender(org.terasology.telemetry.logstash.TelemetryLogstashAppender) Config(org.terasology.config.Config) TelemetryConfig(org.terasology.config.TelemetryConfig) LoggerContext(ch.qos.logback.classic.LoggerContext) TelemetryConfig(org.terasology.config.TelemetryConfig)

Example 2 with TelemetryLogstashAppender

use of org.terasology.telemetry.logstash.TelemetryLogstashAppender in project Terasology by MovingBlocks.

the class TelemetryScreen method pushAddServerPopupAndStartLogBackAppender.

private void pushAddServerPopupAndStartLogBackAppender() {
    AddServerPopup addServerPopup = nuiManager.pushScreen(AddServerPopup.ASSET_URI, AddServerPopup.class);
    addServerPopup.removeTip();
    ServerInfo serverInfo;
    TelemetryConfig telemetryConfig = config.getTelemetryConfig();
    if (telemetryConfig.getErrorReportingDestination() != null) {
        try {
            URL url = new URL("http://" + telemetryConfig.getErrorReportingDestination());
            serverInfo = new ServerInfo(telemetryConfig.getErrorReportingServerName(), url.getHost(), url.getPort());
            serverInfo.setOwner(telemetryConfig.getErrorReportingServerOwner());
        } catch (Exception e) {
            logger.error("Exception when get telemetry server information", e);
            serverInfo = new ServerInfo(TelemetryLogstashAppender.DEFAULT_LOGSTASH_NAME, TelemetryLogstashAppender.DEFAULT_LOGSTASH_HOST, TelemetryLogstashAppender.DEFAULT_LOGSTASH_PORT);
            serverInfo.setOwner(TelemetryLogstashAppender.DEFAULT_LOGSTASH_OWNER);
        }
    } else {
        serverInfo = new ServerInfo(TelemetryLogstashAppender.DEFAULT_LOGSTASH_NAME, TelemetryLogstashAppender.DEFAULT_LOGSTASH_HOST, TelemetryLogstashAppender.DEFAULT_LOGSTASH_PORT);
        serverInfo.setOwner(TelemetryLogstashAppender.DEFAULT_LOGSTASH_OWNER);
    }
    addServerPopup.setServerInfo(serverInfo);
    addServerPopup.onSuccess((item) -> {
        String destinationLogstash = item.getAddress() + ":" + item.getPort();
        TelemetryLogstashAppender telemetryLogstashAppender = TelemetryUtils.fetchTelemetryLogstashAppender();
        if (telemetryLogstashAppender != null) {
            telemetryLogstashAppender.addDestination(destinationLogstash);
            telemetryLogstashAppender.start();
        }
        // Save the destination
        telemetryConfig.setErrorReportingDestination(destinationLogstash);
        telemetryConfig.setErrorReportingServerName(item.getName());
        telemetryConfig.setErrorReportingServerOwner(item.getOwner());
    });
    addServerPopup.onCancel((button) -> telemetryConfig.setErrorReportingEnabled(false));
}
Also used : ServerInfo(org.terasology.config.ServerInfo) TelemetryLogstashAppender(org.terasology.telemetry.logstash.TelemetryLogstashAppender) AddServerPopup(org.terasology.rendering.nui.layers.mainMenu.AddServerPopup) URL(java.net.URL) TelemetryConfig(org.terasology.config.TelemetryConfig)

Example 3 with TelemetryLogstashAppender

use of org.terasology.telemetry.logstash.TelemetryLogstashAppender in project Terasology by MovingBlocks.

the class TelemetryScreen method initialise.

@Override
public void initialise() {
    setAnimationSystem(MenuAnimationSystems.createDefaultSwipeAnimation());
    refreshContent();
    WidgetUtil.trySubscribe(this, "back", button -> triggerBackAnimation());
    WidgetUtil.tryBindCheckBoxWithListener(this, "telemetryEnabled", BindHelper.bindBeanProperty("telemetryEnabled", config.getTelemetryConfig(), Boolean.TYPE), (checkbox) -> {
        if (config.getTelemetryConfig().isTelemetryEnabled()) {
            pushAddServerPopupAndStartEmitter();
        }
    });
    WidgetUtil.tryBindCheckBoxWithListener(this, "errorReportingEnabled", BindHelper.bindBeanProperty("errorReportingEnabled", config.getTelemetryConfig(), Boolean.TYPE), (checkbox) -> {
        if (config.getTelemetryConfig().isErrorReportingEnabled()) {
            pushAddServerPopupAndStartLogBackAppender();
        } else {
            TelemetryLogstashAppender telemetryLogstashAppender = TelemetryUtils.fetchTelemetryLogstashAppender();
            if (telemetryLogstashAppender != null) {
                telemetryLogstashAppender.stop();
            }
        }
    });
    addEnablingAllTelemetryListener();
}
Also used : TelemetryLogstashAppender(org.terasology.telemetry.logstash.TelemetryLogstashAppender)

Example 4 with TelemetryLogstashAppender

use of org.terasology.telemetry.logstash.TelemetryLogstashAppender in project Terasology by MovingBlocks.

the class TelemetryUtils method fetchTelemetryLogstashAppender.

/**
 * Fetch the logstash appender in the logger context.
 * @return the {@link TelemetryLogstashAppender} in the logger context.
 */
public static TelemetryLogstashAppender fetchTelemetryLogstashAppender() {
    TelemetryLogstashAppender appender;
    try {
        LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
        appender = (TelemetryLogstashAppender) lc.getLogger(Logger.ROOT_LOGGER_NAME).getAppender("LOGSTASH");
    } catch (Exception e) {
        logger.error("Error when fetching TelemetryLogstashAppender", e);
        return null;
    }
    return appender;
}
Also used : TelemetryLogstashAppender(org.terasology.telemetry.logstash.TelemetryLogstashAppender) LoggerContext(ch.qos.logback.classic.LoggerContext)

Example 5 with TelemetryLogstashAppender

use of org.terasology.telemetry.logstash.TelemetryLogstashAppender in project Terasology by MovingBlocks.

the class StateMainMenu method pushLaunchPopup.

private void pushLaunchPopup() {
    Config config = context.get(Config.class);
    TelemetryConfig telemetryConfig = config.getTelemetryConfig();
    TranslationSystem translationSystem = context.get(TranslationSystem.class);
    TelemetryLogstashAppender appender = TelemetryUtils.fetchTelemetryLogstashAppender();
    if (!telemetryConfig.isLaunchPopupDisabled()) {
        String telemetryTitle = translationSystem.translate("${engine:menu#telemetry-launch-popup-title}");
        String telemetryMessage = translationSystem.translate("${engine:menu#telemetry-launch-popup-text}");
        LaunchPopup telemetryConfirmPopup = nuiManager.pushScreen(LaunchPopup.ASSET_URI, LaunchPopup.class);
        telemetryConfirmPopup.setMessage(telemetryTitle, telemetryMessage);
        telemetryConfirmPopup.setYesHandler(() -> {
            telemetryConfig.setTelemetryAndErrorReportingEnable(true);
            // Enable error reporting
            appender.start();
        });
        telemetryConfirmPopup.setNoHandler(() -> {
            telemetryConfig.setTelemetryAndErrorReportingEnable(false);
            // Disable error reporting
            appender.stop();
        });
        telemetryConfirmPopup.setOptionButtonText(translationSystem.translate("${engine:menu#telemetry-button}"));
        telemetryConfirmPopup.setOptionHandler(() -> {
            nuiManager.pushScreen(TelemetryScreen.ASSET_URI, TelemetryScreen.class);
        });
    }
}
Also used : TranslationSystem(org.terasology.i18n.TranslationSystem) LaunchPopup(org.terasology.rendering.nui.layers.mainMenu.LaunchPopup) Config(org.terasology.config.Config) TelemetryConfig(org.terasology.config.TelemetryConfig) TelemetryLogstashAppender(org.terasology.telemetry.logstash.TelemetryLogstashAppender) TelemetryConfig(org.terasology.config.TelemetryConfig)

Aggregations

TelemetryLogstashAppender (org.terasology.telemetry.logstash.TelemetryLogstashAppender)5 TelemetryConfig (org.terasology.config.TelemetryConfig)3 LoggerContext (ch.qos.logback.classic.LoggerContext)2 Config (org.terasology.config.Config)2 URL (java.net.URL)1 ServerInfo (org.terasology.config.ServerInfo)1 TranslationSystem (org.terasology.i18n.TranslationSystem)1 AddServerPopup (org.terasology.rendering.nui.layers.mainMenu.AddServerPopup)1 LaunchPopup (org.terasology.rendering.nui.layers.mainMenu.LaunchPopup)1