ch.qos.logback.classic.AsyncAppender Java Examples

The following examples show how to use ch.qos.logback.classic.AsyncAppender. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LoggingConfiguration.java    From alchemy with Apache License 2.0 6 votes vote down vote up
private void addLogstashTcpSocketAppender(LoggerContext context) {
    log.info("Initializing Logstash logging");

    // More documentation is available at: https://github.com/logstash/logstash-logback-encoder
    LogstashTcpSocketAppender logstashAppender = new LogstashTcpSocketAppender();
    logstashAppender.addDestinations(new InetSocketAddress(this.jHipsterProperties.getLogging().getLogstash().getHost(), this.jHipsterProperties.getLogging().getLogstash().getPort()));
    logstashAppender.setContext(context);
    logstashAppender.setEncoder(logstashEncoder());
    logstashAppender.setName(LOGSTASH_APPENDER_NAME);
    logstashAppender.start();

    // Wrap the appender in an Async appender for performance
    AsyncAppender asyncLogstashAppender = new AsyncAppender();
    asyncLogstashAppender.setContext(context);
    asyncLogstashAppender.setName(ASYNC_LOGSTASH_APPENDER_NAME);
    asyncLogstashAppender.setQueueSize(this.jHipsterProperties.getLogging().getLogstash().getQueueSize());
    asyncLogstashAppender.addAppender(logstashAppender);
    asyncLogstashAppender.start();

    context.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME).addAppender(asyncLogstashAppender);
}
 
Example #2
Source File: LoggingConfiguration.java    From java-microservices-examples with Apache License 2.0 6 votes vote down vote up
private void addLogstashTcpSocketAppender(LoggerContext context) {
    log.info("Initializing Logstash logging");

    // More documentation is available at: https://github.com/logstash/logstash-logback-encoder
    LogstashTcpSocketAppender logstashAppender = new LogstashTcpSocketAppender();
    logstashAppender.addDestinations(new InetSocketAddress(this.jHipsterProperties.getLogging().getLogstash().getHost(), this.jHipsterProperties.getLogging().getLogstash().getPort()));
    logstashAppender.setContext(context);
    logstashAppender.setEncoder(logstashEncoder());
    logstashAppender.setName(LOGSTASH_APPENDER_NAME);
    logstashAppender.start();

    // Wrap the appender in an Async appender for performance
    AsyncAppender asyncLogstashAppender = new AsyncAppender();
    asyncLogstashAppender.setContext(context);
    asyncLogstashAppender.setName(ASYNC_LOGSTASH_APPENDER_NAME);
    asyncLogstashAppender.setQueueSize(this.jHipsterProperties.getLogging().getLogstash().getQueueSize());
    asyncLogstashAppender.addAppender(logstashAppender);
    asyncLogstashAppender.start();

    context.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME).addAppender(asyncLogstashAppender);
}
 
Example #3
Source File: LoggingConfiguration.java    From java-microservices-examples with Apache License 2.0 6 votes vote down vote up
private void addLogstashTcpSocketAppender(LoggerContext context) {
    log.info("Initializing Logstash logging");

    // More documentation is available at: https://github.com/logstash/logstash-logback-encoder
    LogstashTcpSocketAppender logstashAppender = new LogstashTcpSocketAppender();
    logstashAppender.addDestinations(new InetSocketAddress(this.jHipsterProperties.getLogging().getLogstash().getHost(), this.jHipsterProperties.getLogging().getLogstash().getPort()));
    logstashAppender.setContext(context);
    logstashAppender.setEncoder(logstashEncoder());
    logstashAppender.setName(LOGSTASH_APPENDER_NAME);
    logstashAppender.start();

    // Wrap the appender in an Async appender for performance
    AsyncAppender asyncLogstashAppender = new AsyncAppender();
    asyncLogstashAppender.setContext(context);
    asyncLogstashAppender.setName(ASYNC_LOGSTASH_APPENDER_NAME);
    asyncLogstashAppender.setQueueSize(this.jHipsterProperties.getLogging().getLogstash().getQueueSize());
    asyncLogstashAppender.addAppender(logstashAppender);
    asyncLogstashAppender.start();

    context.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME).addAppender(asyncLogstashAppender);
}
 
Example #4
Source File: LoggingConfiguration.java    From jhipster-ribbon-hystrix with GNU General Public License v3.0 6 votes vote down vote up
public void addLogstashAppender() {
    log.info("Initializing Logstash logging");

    LogstashSocketAppender logstashAppender = new LogstashSocketAppender();
    logstashAppender.setName("LOGSTASH");
    logstashAppender.setContext(context);
    String customFields = "{\"app_name\":\"" + appName + "\",\"app_port\":\"" + serverPort + "\"," +
        "\"instance_id\":\"" + instanceId + "\"}";
    
    // Set the Logstash appender config from JHipster properties
    logstashAppender.setSyslogHost(jHipsterProperties.getLogging().getLogstash().getHost());
    logstashAppender.setPort(jHipsterProperties.getLogging().getLogstash().getPort());
    logstashAppender.setCustomFields(customFields);
    logstashAppender.start();

    // Wrap the appender in an Async appender for performance
    AsyncAppender asyncLogstashAppender = new AsyncAppender();
    asyncLogstashAppender.setContext(context);
    asyncLogstashAppender.setName("ASYNC_LOGSTASH");
    asyncLogstashAppender.setQueueSize(jHipsterProperties.getLogging().getLogstash().getQueueSize());
    asyncLogstashAppender.addAppender(logstashAppender);
    asyncLogstashAppender.start();

    context.getLogger("ROOT").addAppender(asyncLogstashAppender);
}
 
Example #5
Source File: LoggingConfiguration.java    From jhipster-ribbon-hystrix with GNU General Public License v3.0 6 votes vote down vote up
public void addLogstashAppender() {
    log.info("Initializing Logstash logging");

    LogstashSocketAppender logstashAppender = new LogstashSocketAppender();
    logstashAppender.setName("LOGSTASH");
    logstashAppender.setContext(context);
    String customFields = "{\"app_name\":\"" + appName + "\",\"app_port\":\"" + serverPort + "\"," +
        "\"instance_id\":\"" + instanceId + "\"}";
    
    // Set the Logstash appender config from JHipster properties
    logstashAppender.setSyslogHost(jHipsterProperties.getLogging().getLogstash().getHost());
    logstashAppender.setPort(jHipsterProperties.getLogging().getLogstash().getPort());
    logstashAppender.setCustomFields(customFields);
    logstashAppender.start();

    // Wrap the appender in an Async appender for performance
    AsyncAppender asyncLogstashAppender = new AsyncAppender();
    asyncLogstashAppender.setContext(context);
    asyncLogstashAppender.setName("ASYNC_LOGSTASH");
    asyncLogstashAppender.setQueueSize(jHipsterProperties.getLogging().getLogstash().getQueueSize());
    asyncLogstashAppender.addAppender(logstashAppender);
    asyncLogstashAppender.start();

    context.getLogger("ROOT").addAppender(asyncLogstashAppender);
}
 
Example #6
Source File: LoggingConfiguration.java    From jhipster-ribbon-hystrix with GNU General Public License v3.0 6 votes vote down vote up
public void addLogstashAppender() {
    log.info("Initializing Logstash logging");

    LogstashSocketAppender logstashAppender = new LogstashSocketAppender();
    logstashAppender.setName("LOGSTASH");
    logstashAppender.setContext(context);
    String customFields = "{\"app_name\":\"" + appName + "\",\"app_port\":\"" + serverPort + "\"," +
        "\"instance_id\":\"" + instanceId + "\"}";
    
    // Set the Logstash appender config from JHipster properties
    logstashAppender.setSyslogHost(jHipsterProperties.getLogging().getLogstash().getHost());
    logstashAppender.setPort(jHipsterProperties.getLogging().getLogstash().getPort());
    logstashAppender.setCustomFields(customFields);
    logstashAppender.start();

    // Wrap the appender in an Async appender for performance
    AsyncAppender asyncLogstashAppender = new AsyncAppender();
    asyncLogstashAppender.setContext(context);
    asyncLogstashAppender.setName("ASYNC_LOGSTASH");
    asyncLogstashAppender.setQueueSize(jHipsterProperties.getLogging().getLogstash().getQueueSize());
    asyncLogstashAppender.addAppender(logstashAppender);
    asyncLogstashAppender.start();

    context.getLogger("ROOT").addAppender(asyncLogstashAppender);
}
 
Example #7
Source File: LogBackHookProxy.java    From uavstack with Apache License 2.0 6 votes vote down vote up
private void figureoutLogConfiguration(Logger Logger, LinkedList<LogProfileInfo> list, String appid) {

        Iterator<Appender<ILoggingEvent>> appenders = Logger.iteratorForAppenders();
        while (appenders != null && appenders.hasNext()) {
            Appender<ILoggingEvent> appender = appenders.next();
            if (appender instanceof FileAppender<?>) {
                getAppenderInfo((FileAppender<ILoggingEvent>)appender, list, appid);
            }
            else if(appender instanceof AsyncAppender) {
                Iterator<Appender<ILoggingEvent>> itAppenders = (Iterator<Appender<ILoggingEvent>>)((AsyncAppender) appender).iteratorForAppenders();
                while (itAppenders != null && itAppenders.hasNext()) {
                    Appender<ILoggingEvent> ap = itAppenders.next();
                    if (ap instanceof FileAppender<?>) {
                        getAppenderInfo((FileAppender<ILoggingEvent>)ap, list, appid);
                    }
                } 
            }
        }
    }
 
Example #8
Source File: LoggingConfiguration.java    From 21-points with Apache License 2.0 5 votes vote down vote up
private void addLogstashAppender(LoggerContext context) {
    log.info("Initializing Logstash logging");

    LogstashTcpSocketAppender logstashAppender = new LogstashTcpSocketAppender();
    logstashAppender.setName(LOGSTASH_APPENDER_NAME);
    logstashAppender.setContext(context);
    String customFields = "{\"app_name\":\"" + appName + "\",\"app_port\":\"" + serverPort + "\"}";

    // More documentation is available at: https://github.com/logstash/logstash-logback-encoder
    LogstashEncoder logstashEncoder = new LogstashEncoder();
    // Set the Logstash appender config from JHipster properties
    logstashEncoder.setCustomFields(customFields);
    // Set the Logstash appender config from JHipster properties
    logstashAppender.addDestinations(new InetSocketAddress(jHipsterProperties.getLogging().getLogstash().getHost(), jHipsterProperties.getLogging().getLogstash().getPort()));

    ShortenedThrowableConverter throwableConverter = new ShortenedThrowableConverter();
    throwableConverter.setRootCauseFirst(true);
    logstashEncoder.setThrowableConverter(throwableConverter);
    logstashEncoder.setCustomFields(customFields);

    logstashAppender.setEncoder(logstashEncoder);
    logstashAppender.start();

    // Wrap the appender in an Async appender for performance
    AsyncAppender asyncLogstashAppender = new AsyncAppender();
    asyncLogstashAppender.setContext(context);
    asyncLogstashAppender.setName(ASYNC_LOGSTASH_APPENDER_NAME);
    asyncLogstashAppender.setQueueSize(jHipsterProperties.getLogging().getLogstash().getQueueSize());
    asyncLogstashAppender.addAppender(logstashAppender);
    asyncLogstashAppender.start();

    context.getLogger("ROOT").addAppender(asyncLogstashAppender);
}
 
Example #9
Source File: LoggingConfiguration.java    From tutorials with MIT License 5 votes vote down vote up
public void addLogstashAppender(LoggerContext context) {
    log.info("Initializing Logstash logging");

    LogstashSocketAppender logstashAppender = new LogstashSocketAppender();
    logstashAppender.setName("LOGSTASH");
    logstashAppender.setContext(context);
    String customFields = "{\"app_name\":\"" + appName + "\",\"app_port\":\"" + serverPort + "\"}";

    // Set the Logstash appender config from JHipster properties
    logstashAppender.setSyslogHost(jHipsterProperties.getLogging().getLogstash().getHost());
    logstashAppender.setPort(jHipsterProperties.getLogging().getLogstash().getPort());
    logstashAppender.setCustomFields(customFields);

    // Limit the maximum length of the forwarded stacktrace so that it won't exceed the 8KB UDP limit of logstash
    ShortenedThrowableConverter throwableConverter = new ShortenedThrowableConverter();
    throwableConverter.setMaxLength(7500);
    throwableConverter.setRootCauseFirst(true);
    logstashAppender.setThrowableConverter(throwableConverter);

    logstashAppender.start();

    // Wrap the appender in an Async appender for performance
    AsyncAppender asyncLogstashAppender = new AsyncAppender();
    asyncLogstashAppender.setContext(context);
    asyncLogstashAppender.setName("ASYNC_LOGSTASH");
    asyncLogstashAppender.setQueueSize(jHipsterProperties.getLogging().getLogstash().getQueueSize());
    asyncLogstashAppender.addAppender(logstashAppender);
    asyncLogstashAppender.start();

    context.getLogger("ROOT").addAppender(asyncLogstashAppender);
}
 
Example #10
Source File: LoggingConfiguration.java    From tutorials with MIT License 5 votes vote down vote up
private void addLogstashAppender(LoggerContext context) {
    log.info("Initializing Logstash logging");

    LogstashTcpSocketAppender logstashAppender = new LogstashTcpSocketAppender();
    logstashAppender.setName(LOGSTASH_APPENDER_NAME);
    logstashAppender.setContext(context);
    String optionalFields = "";
    String customFields = "{\"app_name\":\"" + appName + "\",\"app_port\":\"" + serverPort + "\"," +
        optionalFields + "\"version\":\"" + version + "\"}";

    // More documentation is available at: https://github.com/logstash/logstash-logback-encoder
    LogstashEncoder logstashEncoder = new LogstashEncoder();
    // Set the Logstash appender config from JHipster properties
    logstashEncoder.setCustomFields(customFields);
    // Set the Logstash appender config from JHipster properties
    logstashAppender.addDestinations(new InetSocketAddress(jHipsterProperties.getLogging().getLogstash().getHost(), jHipsterProperties.getLogging().getLogstash().getPort()));

    ShortenedThrowableConverter throwableConverter = new ShortenedThrowableConverter();
    throwableConverter.setRootCauseFirst(true);
    logstashEncoder.setThrowableConverter(throwableConverter);
    logstashEncoder.setCustomFields(customFields);

    logstashAppender.setEncoder(logstashEncoder);
    logstashAppender.start();

    // Wrap the appender in an Async appender for performance
    AsyncAppender asyncLogstashAppender = new AsyncAppender();
    asyncLogstashAppender.setContext(context);
    asyncLogstashAppender.setName(ASYNC_LOGSTASH_APPENDER_NAME);
    asyncLogstashAppender.setQueueSize(jHipsterProperties.getLogging().getLogstash().getQueueSize());
    asyncLogstashAppender.addAppender(logstashAppender);
    asyncLogstashAppender.start();

    context.getLogger("ROOT").addAppender(asyncLogstashAppender);
}
 
Example #11
Source File: LoggingConfiguration.java    From tutorials with MIT License 5 votes vote down vote up
private void addLogstashAppender(LoggerContext context) {
    log.info("Initializing Logstash logging");

    LogstashTcpSocketAppender logstashAppender = new LogstashTcpSocketAppender();
    logstashAppender.setName(LOGSTASH_APPENDER_NAME);
    logstashAppender.setContext(context);
    String optionalFields = "";
    String customFields = "{\"app_name\":\"" + appName + "\",\"app_port\":\"" + serverPort + "\"," +
        optionalFields + "\"version\":\"" + version + "\"}";

    // More documentation is available at: https://github.com/logstash/logstash-logback-encoder
    LogstashEncoder logstashEncoder = new LogstashEncoder();
    // Set the Logstash appender config from JHipster properties
    logstashEncoder.setCustomFields(customFields);
    // Set the Logstash appender config from JHipster properties
    logstashAppender.addDestinations(new InetSocketAddress(jHipsterProperties.getLogging().getLogstash().getHost(), jHipsterProperties.getLogging().getLogstash().getPort()));

    ShortenedThrowableConverter throwableConverter = new ShortenedThrowableConverter();
    throwableConverter.setRootCauseFirst(true);
    logstashEncoder.setThrowableConverter(throwableConverter);
    logstashEncoder.setCustomFields(customFields);

    logstashAppender.setEncoder(logstashEncoder);
    logstashAppender.start();

    // Wrap the appender in an Async appender for performance
    AsyncAppender asyncLogstashAppender = new AsyncAppender();
    asyncLogstashAppender.setContext(context);
    asyncLogstashAppender.setName(ASYNC_LOGSTASH_APPENDER_NAME);
    asyncLogstashAppender.setQueueSize(jHipsterProperties.getLogging().getLogstash().getQueueSize());
    asyncLogstashAppender.addAppender(logstashAppender);
    asyncLogstashAppender.start();

    context.getLogger("ROOT").addAppender(asyncLogstashAppender);
}
 
Example #12
Source File: LoggingConfiguration.java    From tutorials with MIT License 5 votes vote down vote up
private void addLogstashAppender(LoggerContext context) {
    log.info("Initializing Logstash logging");

    LogstashTcpSocketAppender logstashAppender = new LogstashTcpSocketAppender();
    logstashAppender.setName(LOGSTASH_APPENDER_NAME);
    logstashAppender.setContext(context);
    String optionalFields = "";
    String customFields = "{\"app_name\":\"" + appName + "\",\"app_port\":\"" + serverPort + "\"," +
        optionalFields + "\"version\":\"" + version + "\"}";

    // More documentation is available at: https://github.com/logstash/logstash-logback-encoder
    LogstashEncoder logstashEncoder = new LogstashEncoder();
    // Set the Logstash appender config from JHipster properties
    logstashEncoder.setCustomFields(customFields);
    // Set the Logstash appender config from JHipster properties
    logstashAppender.addDestinations(new InetSocketAddress(jHipsterProperties.getLogging().getLogstash().getHost(), jHipsterProperties.getLogging().getLogstash().getPort()));

    ShortenedThrowableConverter throwableConverter = new ShortenedThrowableConverter();
    throwableConverter.setRootCauseFirst(true);
    logstashEncoder.setThrowableConverter(throwableConverter);
    logstashEncoder.setCustomFields(customFields);

    logstashAppender.setEncoder(logstashEncoder);
    logstashAppender.start();

    // Wrap the appender in an Async appender for performance
    AsyncAppender asyncLogstashAppender = new AsyncAppender();
    asyncLogstashAppender.setContext(context);
    asyncLogstashAppender.setName(ASYNC_LOGSTASH_APPENDER_NAME);
    asyncLogstashAppender.setQueueSize(jHipsterProperties.getLogging().getLogstash().getQueueSize());
    asyncLogstashAppender.addAppender(logstashAppender);
    asyncLogstashAppender.start();

    context.getLogger("ROOT").addAppender(asyncLogstashAppender);
}
 
Example #13
Source File: LoggingConfiguration.java    From tutorials with MIT License 5 votes vote down vote up
public void addLogstashAppender(LoggerContext context) {
    log.info("Initializing Logstash logging");

    LogstashSocketAppender logstashAppender = new LogstashSocketAppender();
    logstashAppender.setName("LOGSTASH");
    logstashAppender.setContext(context);
    String customFields = "{\"app_name\":\"" + appName + "\",\"app_port\":\"" + serverPort + "\"," +
        "\"instance_id\":\"" + instanceId + "\"}";

    // Set the Logstash appender config from JHipster properties
    logstashAppender.setSyslogHost(jHipsterProperties.getLogging().getLogstash().getHost());
    logstashAppender.setPort(jHipsterProperties.getLogging().getLogstash().getPort());
    logstashAppender.setCustomFields(customFields);

    // Limit the maximum length of the forwarded stacktrace so that it won't exceed the 8KB UDP limit of logstash
    ShortenedThrowableConverter throwableConverter = new ShortenedThrowableConverter();
    throwableConverter.setMaxLength(7500);
    throwableConverter.setRootCauseFirst(true);
    logstashAppender.setThrowableConverter(throwableConverter);

    logstashAppender.start();

    // Wrap the appender in an Async appender for performance
    AsyncAppender asyncLogstashAppender = new AsyncAppender();
    asyncLogstashAppender.setContext(context);
    asyncLogstashAppender.setName("ASYNC_LOGSTASH");
    asyncLogstashAppender.setQueueSize(jHipsterProperties.getLogging().getLogstash().getQueueSize());
    asyncLogstashAppender.addAppender(logstashAppender);
    asyncLogstashAppender.start();

    context.getLogger("ROOT").addAppender(asyncLogstashAppender);
}
 
Example #14
Source File: LoggingConfiguration.java    From tutorials with MIT License 5 votes vote down vote up
private void addLogstashAppender(LoggerContext context) {
    log.info("Initializing Logstash logging");

    LogstashTcpSocketAppender logstashAppender = new LogstashTcpSocketAppender();
    logstashAppender.setName(LOGSTASH_APPENDER_NAME);
    logstashAppender.setContext(context);
    String customFields = "{\"app_name\":\"" + appName + "\",\"app_port\":\"" + serverPort + "\"}";

    // More documentation is available at: https://github.com/logstash/logstash-logback-encoder
    LogstashEncoder logstashEncoder = new LogstashEncoder();
    // Set the Logstash appender config from JHipster properties
    logstashAppender.addDestinations(new InetSocketAddress(jHipsterProperties.getLogging().getLogstash().getHost(), jHipsterProperties.getLogging().getLogstash().getPort()));

    ShortenedThrowableConverter throwableConverter = new ShortenedThrowableConverter();
    throwableConverter.setRootCauseFirst(true);
    logstashEncoder.setThrowableConverter(throwableConverter);
    logstashEncoder.setCustomFields(customFields);

    logstashAppender.setEncoder(logstashEncoder);
    logstashAppender.start();

    // Wrap the appender in an Async appender for performance
    AsyncAppender asyncLogstashAppender = new AsyncAppender();
    asyncLogstashAppender.setContext(context);
    asyncLogstashAppender.setName(ASYNC_LOGSTASH_APPENDER_NAME);
    asyncLogstashAppender.setQueueSize(jHipsterProperties.getLogging().getLogstash().getQueueSize());
    asyncLogstashAppender.addAppender(logstashAppender);
    asyncLogstashAppender.start();

    context.getLogger("ROOT").addAppender(asyncLogstashAppender);
}
 
Example #15
Source File: LoggingConfiguration.java    From OpenIoE with Apache License 2.0 5 votes vote down vote up
public void addLogstashAppender() {
    log.info("Initializing Logstash logging");

    LogstashSocketAppender logstashAppender = new LogstashSocketAppender();
    logstashAppender.setName("LOGSTASH");
    logstashAppender.setContext(context);

    String customFields = "{\"app_name\":\"" + appName + "\",\"app_port\":\"" + serverPort + "\"}";

    // Set the Logstash appender config from JHipster properties
    logstashAppender.setSyslogHost(jHipsterProperties.getLogging().getLogstash().getHost());
    logstashAppender.setPort(jHipsterProperties.getLogging().getLogstash().getPort());
    logstashAppender.setCustomFields(customFields);

    // Limit the maximum length of the forwarded stacktrace so that it won't exceed the 8KB UDP limit of logstash
    ShortenedThrowableConverter throwableConverter = new ShortenedThrowableConverter();
    throwableConverter.setMaxLength(7500);
    throwableConverter.setRootCauseFirst(true);
    logstashAppender.setThrowableConverter(throwableConverter);

    logstashAppender.start();

    // Wrap the appender in an Async appender for performance
    AsyncAppender asyncLogstashAppender = new AsyncAppender();
    asyncLogstashAppender.setContext(context);
    asyncLogstashAppender.setName("ASYNC_LOGSTASH");
    asyncLogstashAppender.setQueueSize(jHipsterProperties.getLogging().getLogstash().getQueueSize());
    asyncLogstashAppender.addAppender(logstashAppender);
    asyncLogstashAppender.start();

    context.getLogger("ROOT").addAppender(asyncLogstashAppender);
}
 
Example #16
Source File: LoggingConfiguration.java    From flair-engine with Apache License 2.0 5 votes vote down vote up
public void addLogstashAppender(LoggerContext context) {
    log.info("Initializing Logstash logging");

    LogstashSocketAppender logstashAppender = new LogstashSocketAppender();
    logstashAppender.setName("LOGSTASH");
    logstashAppender.setContext(context);
    String customFields = "{\"app_name\":\"" + appName + "\",\"app_port\":\"" + serverPort + "\"}";

    // Set the Logstash appender config from JHipster properties
    logstashAppender.setSyslogHost(jHipsterProperties.getLogging().getLogstash().getHost());
    logstashAppender.setPort(jHipsterProperties.getLogging().getLogstash().getPort());
    logstashAppender.setCustomFields(customFields);

    // Limit the maximum length of the forwarded stacktrace so that it won't exceed the 8KB UDP limit of logstash
    ShortenedThrowableConverter throwableConverter = new ShortenedThrowableConverter();
    throwableConverter.setMaxLength(7500);
    throwableConverter.setRootCauseFirst(true);
    logstashAppender.setThrowableConverter(throwableConverter);

    logstashAppender.start();

    // Wrap the appender in an Async appender for performance
    AsyncAppender asyncLogstashAppender = new AsyncAppender();
    asyncLogstashAppender.setContext(context);
    asyncLogstashAppender.setName("ASYNC_LOGSTASH");
    asyncLogstashAppender.setQueueSize(jHipsterProperties.getLogging().getLogstash().getQueueSize());
    asyncLogstashAppender.addAppender(logstashAppender);
    asyncLogstashAppender.start();

    context.getLogger("ROOT").addAppender(asyncLogstashAppender);
}
 
Example #17
Source File: LoggingConfiguration.java    From ehcache3-samples with Apache License 2.0 5 votes vote down vote up
private void addLogstashAppender(LoggerContext context) {
    log.info("Initializing Logstash logging");

    LogstashTcpSocketAppender logstashAppender = new LogstashTcpSocketAppender();
    logstashAppender.setName(LOGSTASH_APPENDER_NAME);
    logstashAppender.setContext(context);
    String customFields = "{\"app_name\":\"" + appName + "\",\"app_port\":\"" + serverPort + "\"}";

    // More documentation is available at: https://github.com/logstash/logstash-logback-encoder
    LogstashEncoder logstashEncoder = new LogstashEncoder();
    // Set the Logstash appender config from JHipster properties
    logstashEncoder.setCustomFields(customFields);
    // Set the Logstash appender config from JHipster properties
    logstashAppender.addDestinations(new InetSocketAddress(jHipsterProperties.getLogging().getLogstash().getHost(), jHipsterProperties.getLogging().getLogstash().getPort()));

    ShortenedThrowableConverter throwableConverter = new ShortenedThrowableConverter();
    throwableConverter.setRootCauseFirst(true);
    logstashEncoder.setThrowableConverter(throwableConverter);
    logstashEncoder.setCustomFields(customFields);

    logstashAppender.setEncoder(logstashEncoder);
    logstashAppender.start();

    // Wrap the appender in an Async appender for performance
    AsyncAppender asyncLogstashAppender = new AsyncAppender();
    asyncLogstashAppender.setContext(context);
    asyncLogstashAppender.setName(ASYNC_LOGSTASH_APPENDER_NAME);
    asyncLogstashAppender.setQueueSize(jHipsterProperties.getLogging().getLogstash().getQueueSize());
    asyncLogstashAppender.addAppender(logstashAppender);
    asyncLogstashAppender.start();

    context.getLogger("ROOT").addAppender(asyncLogstashAppender);
}
 
Example #18
Source File: LoggingConfiguration.java    From gpmr with Apache License 2.0 5 votes vote down vote up
public void addLogstashAppender() {
    log.info("Initializing Logstash logging");

    LogstashSocketAppender logstashAppender = new LogstashSocketAppender();
    logstashAppender.setName("LOGSTASH");
    logstashAppender.setContext(context);

    String customFields = "{\"app_name\":\"" + appName + "\",\"app_port\":\"" + serverPort + "\"}";

    // Set the Logstash appender config from JHipster properties
    logstashAppender.setSyslogHost(jHipsterProperties.getLogging().getLogstash().getHost());
    logstashAppender.setPort(jHipsterProperties.getLogging().getLogstash().getPort());
    logstashAppender.setCustomFields(customFields);

    // Limit the maximum length of the forwarded stacktrace so that it won't exceed the 8KB UDP limit of logstash
    ShortenedThrowableConverter throwableConverter = new ShortenedThrowableConverter();
    throwableConverter.setMaxLength(7500);
    throwableConverter.setRootCauseFirst(true);
    logstashAppender.setThrowableConverter(throwableConverter);

    logstashAppender.start();

    // Wrap the appender in an Async appender for performance
    AsyncAppender asyncLogstashAppender = new AsyncAppender();
    asyncLogstashAppender.setContext(context);
    asyncLogstashAppender.setName("ASYNC_LOGSTASH");
    asyncLogstashAppender.setQueueSize(jHipsterProperties.getLogging().getLogstash().getQueueSize());
    asyncLogstashAppender.addAppender(logstashAppender);
    asyncLogstashAppender.start();

    context.getLogger("ROOT").addAppender(asyncLogstashAppender);
}
 
Example #19
Source File: LogbackSlowQueryLogProvider.java    From emodb with Apache License 2.0 5 votes vote down vote up
@Override
public SlowQueryLog get() {
    Logger logger = (Logger) LoggerFactory.getLogger("sor.slow-query");
    logger.setAdditive(false);
    LoggerContext context = logger.getLoggerContext();
    logger.detachAndStopAllAppenders();

    PatternLayout logPatternLayout = new PatternLayout();
    logPatternLayout.setPattern("%-5p [%d{ISO8601," + _config.getTimeZone().getID() + "}] %m\n");
    logPatternLayout.setContext(context);
    logPatternLayout.start();

    ConsoleAppenderFactory consoleAppenderFactory = _config.getConsoleAppenderFactory();
    if (consoleAppenderFactory != null) {
        // Console is usually used only in development.  Use a synchronous appender so console output doesn't get re-ordered.
        logger.addAppender(consoleAppenderFactory.build(context, EMODB_APPLICATION_NAME, logPatternLayout));
    }

    FileAppenderFactory fileAppenderFactory = _config.getFileAppenderFactory();
    if (fileAppenderFactory != null) {
        AsyncAppender fileAsyncAppender = new AsyncAppender();
        fileAsyncAppender.addAppender(fileAppenderFactory.build(context, EMODB_APPLICATION_NAME, logPatternLayout));
        fileAsyncAppender.start();
        logger.addAppender(fileAsyncAppender);
    }

    SyslogAppenderFactory syslogAppenderFactory = _config.getSyslogAppenderFactory();
    if (syslogAppenderFactory != null) {
        AsyncAppender sysAsyncAppender = new AsyncAppender();
        sysAsyncAppender.addAppender(syslogAppenderFactory.build(context, EMODB_APPLICATION_NAME, logPatternLayout));
        sysAsyncAppender.start();
        logger.addAppender(sysAsyncAppender);
    }

    return new LogbackSlowQueryLog(logger, _config.getTooManyDeltasThreshold(), _metricRegistry);
}
 
Example #20
Source File: ChameleonInstanceHolder.java    From wisdom with Apache License 2.0 5 votes vote down vote up
/**
 * Fixes the Chameleon logging configuration to write the logs in the logs/wisdom.log file instead of chameleon.log
 * file.
 *
 * @param basedir the base directory of the chameleon
 */
public static void fixLoggingSystem(File basedir) {
    ILoggerFactory factory = LoggerFactory.getILoggerFactory();
    if (factory instanceof LoggerContext) {
        // We know that we are using logback from here.
        LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
        ch.qos.logback.classic.Logger logbackLogger = lc.getLogger(Logger.ROOT_LOGGER_NAME);
        if (logbackLogger == null) {
            return;
        }

        Iterator<Appender<ILoggingEvent>> iterator = logbackLogger.iteratorForAppenders();
        while (iterator.hasNext()) {
            Appender<ILoggingEvent> appender = iterator.next();

            if (appender instanceof AsyncAppender) {
                appender = ((AsyncAppender) appender).getAppender("FILE");
            }

            if (appender instanceof RollingFileAppender) {
                RollingFileAppender<ILoggingEvent> fileAppender =
                        (RollingFileAppender<ILoggingEvent>) appender;
                String file = new File(basedir, "logs/wisdom.log").getAbsolutePath();
                fileAppender.stop();
                // Remove the created log directory.
                // We do that afterwards because on Windows the file cannot be deleted while we still have a logger
                // using it.
                FileUtils.deleteQuietly(new File("logs"));
                fileAppender.setFile(file);
                fileAppender.setContext(lc);
                fileAppender.start();
            }
        }
    }
}
 
Example #21
Source File: LoggingConfiguration.java    From tutorials with MIT License 5 votes vote down vote up
public void addLogstashAppender(LoggerContext context) {
    log.info("Initializing Logstash logging");

    LogstashSocketAppender logstashAppender = new LogstashSocketAppender();
    logstashAppender.setName("LOGSTASH");
    logstashAppender.setContext(context);
    String customFields = "{\"app_name\":\"" + appName + "\",\"app_port\":\"" + serverPort + "\"," +
        "\"instance_id\":\"" + instanceId + "\"}";

    // Set the Logstash appender config from JHipster properties
    logstashAppender.setSyslogHost(jHipsterProperties.getLogging().getLogstash().getHost());
    logstashAppender.setPort(jHipsterProperties.getLogging().getLogstash().getPort());
    logstashAppender.setCustomFields(customFields);

    // Limit the maximum length of the forwarded stacktrace so that it won't exceed the 8KB UDP limit of logstash
    ShortenedThrowableConverter throwableConverter = new ShortenedThrowableConverter();
    throwableConverter.setMaxLength(7500);
    throwableConverter.setRootCauseFirst(true);
    logstashAppender.setThrowableConverter(throwableConverter);

    logstashAppender.start();

    // Wrap the appender in an Async appender for performance
    AsyncAppender asyncLogstashAppender = new AsyncAppender();
    asyncLogstashAppender.setContext(context);
    asyncLogstashAppender.setName("ASYNC_LOGSTASH");
    asyncLogstashAppender.setQueueSize(jHipsterProperties.getLogging().getLogstash().getQueueSize());
    asyncLogstashAppender.addAppender(logstashAppender);
    asyncLogstashAppender.start();

    context.getLogger("ROOT").addAppender(asyncLogstashAppender);
}
 
Example #22
Source File: LoggingConfiguration.java    From klask-io with GNU General Public License v3.0 5 votes vote down vote up
public void addLogstashAppender() {
    log.info("Initializing Logstash logging");

    LogstashSocketAppender logstashAppender = new LogstashSocketAppender();
    logstashAppender.setName("LOGSTASH");
    logstashAppender.setContext(context);

    String customFields = "{\"app_name\":\"" + appName + "\",\"app_port\":\"" + serverPort + "\"}";

    // Set the Logstash appender config from JHipster properties
    logstashAppender.setSyslogHost(jHipsterProperties.getLogging().getLogstash().getHost());
    logstashAppender.setPort(jHipsterProperties.getLogging().getLogstash().getPort());
    logstashAppender.setCustomFields(customFields);

    // Limit the maximum length of the forwarded stacktrace so that it won't exceed the 8KB UDP limit of logstash
    ShortenedThrowableConverter throwableConverter = new ShortenedThrowableConverter();
    throwableConverter.setMaxLength(7500);
    throwableConverter.setRootCauseFirst(true);
    logstashAppender.setThrowableConverter(throwableConverter);

    logstashAppender.start();

    // Wrap the appender in an Async appender for performance
    AsyncAppender asyncLogstashAppender = new AsyncAppender();
    asyncLogstashAppender.setContext(context);
    asyncLogstashAppender.setName("ASYNC_LOGSTASH");
    asyncLogstashAppender.setQueueSize(jHipsterProperties.getLogging().getLogstash().getQueueSize());
    asyncLogstashAppender.addAppender(logstashAppender);
    asyncLogstashAppender.start();

    context.getLogger("ROOT").addAppender(asyncLogstashAppender);
}
 
Example #23
Source File: LoggingConfiguration.java    From jhipster-microservices-example with Apache License 2.0 5 votes vote down vote up
public void addLogstashAppender(LoggerContext context) {
    log.info("Initializing Logstash logging");

    LogstashSocketAppender logstashAppender = new LogstashSocketAppender();
    logstashAppender.setName("LOGSTASH");
    logstashAppender.setContext(context);
    String customFields = "{\"app_name\":\"" + appName + "\",\"app_port\":\"" + serverPort + "\"," +
        "\"instance_id\":\"" + instanceId + "\"}";

    // Set the Logstash appender config from JHipster properties
    logstashAppender.setSyslogHost(jHipsterProperties.getLogging().getLogstash().getHost());
    logstashAppender.setPort(jHipsterProperties.getLogging().getLogstash().getPort());
    logstashAppender.setCustomFields(customFields);

    // Limit the maximum length of the forwarded stacktrace so that it won't exceed the 8KB UDP limit of logstash
    ShortenedThrowableConverter throwableConverter = new ShortenedThrowableConverter();
    throwableConverter.setMaxLength(7500);
    throwableConverter.setRootCauseFirst(true);
    logstashAppender.setThrowableConverter(throwableConverter);

    logstashAppender.start();

    // Wrap the appender in an Async appender for performance
    AsyncAppender asyncLogstashAppender = new AsyncAppender();
    asyncLogstashAppender.setContext(context);
    asyncLogstashAppender.setName("ASYNC_LOGSTASH");
    asyncLogstashAppender.setQueueSize(jHipsterProperties.getLogging().getLogstash().getQueueSize());
    asyncLogstashAppender.addAppender(logstashAppender);
    asyncLogstashAppender.start();

    context.getLogger("ROOT").addAppender(asyncLogstashAppender);
}
 
Example #24
Source File: LoggingConfiguration.java    From jhipster-microservices-example with Apache License 2.0 5 votes vote down vote up
public void addLogstashAppender(LoggerContext context) {
    log.info("Initializing Logstash logging");

    LogstashSocketAppender logstashAppender = new LogstashSocketAppender();
    logstashAppender.setName("LOGSTASH");
    logstashAppender.setContext(context);
    String customFields = "{\"app_name\":\"" + appName + "\",\"app_port\":\"" + serverPort + "\"," +
        "\"instance_id\":\"" + instanceId + "\"}";

    // Set the Logstash appender config from JHipster properties
    logstashAppender.setSyslogHost(jHipsterProperties.getLogging().getLogstash().getHost());
    logstashAppender.setPort(jHipsterProperties.getLogging().getLogstash().getPort());
    logstashAppender.setCustomFields(customFields);

    // Limit the maximum length of the forwarded stacktrace so that it won't exceed the 8KB UDP limit of logstash
    ShortenedThrowableConverter throwableConverter = new ShortenedThrowableConverter();
    throwableConverter.setMaxLength(7500);
    throwableConverter.setRootCauseFirst(true);
    logstashAppender.setThrowableConverter(throwableConverter);

    logstashAppender.start();

    // Wrap the appender in an Async appender for performance
    AsyncAppender asyncLogstashAppender = new AsyncAppender();
    asyncLogstashAppender.setContext(context);
    asyncLogstashAppender.setName("ASYNC_LOGSTASH");
    asyncLogstashAppender.setQueueSize(jHipsterProperties.getLogging().getLogstash().getQueueSize());
    asyncLogstashAppender.addAppender(logstashAppender);
    asyncLogstashAppender.start();

    context.getLogger("ROOT").addAppender(asyncLogstashAppender);
}
 
Example #25
Source File: LoggingConfiguration.java    From jhipster-microservices-example with Apache License 2.0 5 votes vote down vote up
public void addLogstashAppender(LoggerContext context) {
    log.info("Initializing Logstash logging");

    LogstashSocketAppender logstashAppender = new LogstashSocketAppender();
    logstashAppender.setName("LOGSTASH");
    logstashAppender.setContext(context);
    String customFields = "{\"app_name\":\"" + appName + "\",\"app_port\":\"" + serverPort + "\"," +
        "\"instance_id\":\"" + instanceId + "\"}";

    // Set the Logstash appender config from JHipster properties
    logstashAppender.setSyslogHost(jHipsterProperties.getLogging().getLogstash().getHost());
    logstashAppender.setPort(jHipsterProperties.getLogging().getLogstash().getPort());
    logstashAppender.setCustomFields(customFields);

    // Limit the maximum length of the forwarded stacktrace so that it won't exceed the 8KB UDP limit of logstash
    ShortenedThrowableConverter throwableConverter = new ShortenedThrowableConverter();
    throwableConverter.setMaxLength(7500);
    throwableConverter.setRootCauseFirst(true);
    logstashAppender.setThrowableConverter(throwableConverter);

    logstashAppender.start();

    // Wrap the appender in an Async appender for performance
    AsyncAppender asyncLogstashAppender = new AsyncAppender();
    asyncLogstashAppender.setContext(context);
    asyncLogstashAppender.setName("ASYNC_LOGSTASH");
    asyncLogstashAppender.setQueueSize(jHipsterProperties.getLogging().getLogstash().getQueueSize());
    asyncLogstashAppender.addAppender(logstashAppender);
    asyncLogstashAppender.start();

    context.getLogger("ROOT").addAppender(asyncLogstashAppender);
}
 
Example #26
Source File: LogbackHelper.java    From arthas with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("rawtypes")
private static List<Map<String, Object>> doGetLoggerAppenders(Iterator<Appender<ILoggingEvent>> appenders) {
    List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();

    while (appenders.hasNext()) {
        Map<String, Object> info = new LinkedHashMap<String, Object>();
        Appender<ILoggingEvent> appender = appenders.next();
        info.put(LoggerHelper.name, appender.getName());
        info.put(LoggerHelper.clazz, appender.getClass());
        if (appender instanceof FileAppender) {
            info.put(LoggerHelper.file, ((FileAppender) appender).getFile());
        } else if (appender instanceof AsyncAppender) {
            AsyncAppender aa = (AsyncAppender) appender;
            Iterator<Appender<ILoggingEvent>> iter = aa.iteratorForAppenders();
            List<Map<String, Object>> asyncs = doGetLoggerAppenders(iter);

            // 异步appender所 ref的 appender,参考: https://logback.qos.ch/manual/appenders.html
            List<String> appenderRef = new ArrayList<String>();
            for (Map<String, Object> a : asyncs) {
                appenderRef.add((String) a.get(LoggerHelper.name));
                result.add(a);
            }
            info.put(LoggerHelper.appenderRef, appenderRef);
            info.put(LoggerHelper.blocking, !aa.isNeverBlock());
        } else if (appender instanceof ConsoleAppender) {
            info.put(LoggerHelper.target, ((ConsoleAppender) appender).getTarget());
        }
        result.add(info);
    }

    return result;
}
 
Example #27
Source File: LoggingConfiguration.java    From Full-Stack-Development-with-JHipster with MIT License 5 votes vote down vote up
private void addLogstashAppender(LoggerContext context) {
    log.info("Initializing Logstash logging");

    LogstashTcpSocketAppender logstashAppender = new LogstashTcpSocketAppender();
    logstashAppender.setName(LOGSTASH_APPENDER_NAME);
    logstashAppender.setContext(context);
    String customFields = "{\"app_name\":\"" + appName + "\",\"app_port\":\"" + serverPort + "\"}";

    // More documentation is available at: https://github.com/logstash/logstash-logback-encoder
    LogstashEncoder logstashEncoder=new LogstashEncoder();
    // Set the Logstash appender config from JHipster properties
    logstashEncoder.setCustomFields(customFields);
    // Set the Logstash appender config from JHipster properties
    logstashAppender.addDestinations(new InetSocketAddress(jHipsterProperties.getLogging().getLogstash().getHost(),jHipsterProperties.getLogging().getLogstash().getPort()));

    ShortenedThrowableConverter throwableConverter = new ShortenedThrowableConverter();
    throwableConverter.setRootCauseFirst(true);
    logstashEncoder.setThrowableConverter(throwableConverter);
    logstashEncoder.setCustomFields(customFields);

    logstashAppender.setEncoder(logstashEncoder);
    logstashAppender.start();

    // Wrap the appender in an Async appender for performance
    AsyncAppender asyncLogstashAppender = new AsyncAppender();
    asyncLogstashAppender.setContext(context);
    asyncLogstashAppender.setName(ASYNC_LOGSTASH_APPENDER_NAME);
    asyncLogstashAppender.setQueueSize(jHipsterProperties.getLogging().getLogstash().getQueueSize());
    asyncLogstashAppender.addAppender(logstashAppender);
    asyncLogstashAppender.start();

    context.getLogger("ROOT").addAppender(asyncLogstashAppender);
}
 
Example #28
Source File: LoggingConfiguration.java    From e-commerce-microservice with Apache License 2.0 5 votes vote down vote up
private void addLogstashAppender(LoggerContext context) {
    log.info("Initializing Logstash logging");

    LogstashTcpSocketAppender logstashAppender = new LogstashTcpSocketAppender();
    logstashAppender.setName(LOGSTASH_APPENDER_NAME);
    logstashAppender.setContext(context);
    String optionalFields = "";
    String customFields = "{\"app_name\":\"" + appName + "\",\"app_port\":\"" + serverPort + "\"," +
        optionalFields + "\"version\":\"" + version + "\"}";

    // More documentation is available at: https://github.com/logstash/logstash-logback-encoder
    LogstashEncoder logstashEncoder = new LogstashEncoder();
    // Set the Logstash appender config from JHipster properties
    logstashEncoder.setCustomFields(customFields);
    // Set the Logstash appender config from JHipster properties
    logstashAppender.addDestinations(new InetSocketAddress(jHipsterProperties.getLogging().getLogstash().getHost(), jHipsterProperties.getLogging().getLogstash().getPort()));

    ShortenedThrowableConverter throwableConverter = new ShortenedThrowableConverter();
    throwableConverter.setRootCauseFirst(true);
    logstashEncoder.setThrowableConverter(throwableConverter);
    logstashEncoder.setCustomFields(customFields);

    logstashAppender.setEncoder(logstashEncoder);
    logstashAppender.start();

    // Wrap the appender in an Async appender for performance
    AsyncAppender asyncLogstashAppender = new AsyncAppender();
    asyncLogstashAppender.setContext(context);
    asyncLogstashAppender.setName(ASYNC_LOGSTASH_APPENDER_NAME);
    asyncLogstashAppender.setQueueSize(jHipsterProperties.getLogging().getLogstash().getQueueSize());
    asyncLogstashAppender.addAppender(logstashAppender);
    asyncLogstashAppender.start();

    context.getLogger("ROOT").addAppender(asyncLogstashAppender);
}
 
Example #29
Source File: LoggingConfiguration.java    From e-commerce-microservice with Apache License 2.0 5 votes vote down vote up
private void addLogstashAppender(LoggerContext context) {
    log.info("Initializing Logstash logging");

    LogstashTcpSocketAppender logstashAppender = new LogstashTcpSocketAppender();
    logstashAppender.setName(LOGSTASH_APPENDER_NAME);
    logstashAppender.setContext(context);
    String optionalFields = "";
    String customFields = "{\"app_name\":\"" + appName + "\",\"app_port\":\"" + serverPort + "\"," +
        optionalFields + "\"version\":\"" + version + "\"}";

    // More documentation is available at: https://github.com/logstash/logstash-logback-encoder
    LogstashEncoder logstashEncoder = new LogstashEncoder();
    // Set the Logstash appender config from JHipster properties
    logstashEncoder.setCustomFields(customFields);
    // Set the Logstash appender config from JHipster properties
    logstashAppender.addDestinations(new InetSocketAddress(jHipsterProperties.getLogging().getLogstash().getHost(), jHipsterProperties.getLogging().getLogstash().getPort()));

    ShortenedThrowableConverter throwableConverter = new ShortenedThrowableConverter();
    throwableConverter.setRootCauseFirst(true);
    logstashEncoder.setThrowableConverter(throwableConverter);
    logstashEncoder.setCustomFields(customFields);

    logstashAppender.setEncoder(logstashEncoder);
    logstashAppender.start();

    // Wrap the appender in an Async appender for performance
    AsyncAppender asyncLogstashAppender = new AsyncAppender();
    asyncLogstashAppender.setContext(context);
    asyncLogstashAppender.setName(ASYNC_LOGSTASH_APPENDER_NAME);
    asyncLogstashAppender.setQueueSize(jHipsterProperties.getLogging().getLogstash().getQueueSize());
    asyncLogstashAppender.addAppender(logstashAppender);
    asyncLogstashAppender.start();

    context.getLogger("ROOT").addAppender(asyncLogstashAppender);
}
 
Example #30
Source File: LoggingConfiguration.java    From e-commerce-microservice with Apache License 2.0 5 votes vote down vote up
private void addLogstashAppender(LoggerContext context) {
    log.info("Initializing Logstash logging");

    LogstashTcpSocketAppender logstashAppender = new LogstashTcpSocketAppender();
    logstashAppender.setName(LOGSTASH_APPENDER_NAME);
    logstashAppender.setContext(context);
    String optionalFields = "";
    String customFields = "{\"app_name\":\"" + appName + "\",\"app_port\":\"" + serverPort + "\"," +
        optionalFields + "\"version\":\"" + version + "\"}";

    // More documentation is available at: https://github.com/logstash/logstash-logback-encoder
    LogstashEncoder logstashEncoder = new LogstashEncoder();
    // Set the Logstash appender config from JHipster properties
    logstashEncoder.setCustomFields(customFields);
    // Set the Logstash appender config from JHipster properties
    logstashAppender.addDestinations(new InetSocketAddress(jHipsterProperties.getLogging().getLogstash().getHost(), jHipsterProperties.getLogging().getLogstash().getPort()));

    ShortenedThrowableConverter throwableConverter = new ShortenedThrowableConverter();
    throwableConverter.setRootCauseFirst(true);
    logstashEncoder.setThrowableConverter(throwableConverter);
    logstashEncoder.setCustomFields(customFields);

    logstashAppender.setEncoder(logstashEncoder);
    logstashAppender.start();

    // Wrap the appender in an Async appender for performance
    AsyncAppender asyncLogstashAppender = new AsyncAppender();
    asyncLogstashAppender.setContext(context);
    asyncLogstashAppender.setName(ASYNC_LOGSTASH_APPENDER_NAME);
    asyncLogstashAppender.setQueueSize(jHipsterProperties.getLogging().getLogstash().getQueueSize());
    asyncLogstashAppender.addAppender(logstashAppender);
    asyncLogstashAppender.start();

    context.getLogger("ROOT").addAppender(asyncLogstashAppender);
}