Java Code Examples for net.logstash.logback.appender.LogstashTcpSocketAppender#setName()

The following examples show how to use net.logstash.logback.appender.LogstashTcpSocketAppender#setName() . 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: LoggingUtils.java    From jhipster with Apache License 2.0 6 votes vote down vote up
/**
 * <p>addLogstashTcpSocketAppender.</p>
 *
 * @param context a {@link ch.qos.logback.classic.LoggerContext} object.
 * @param customFields a {@link java.lang.String} object.
 * @param logstashProperties a {@link io.github.jhipster.config.JHipsterProperties.Logging.Logstash} object.
 */
public static void addLogstashTcpSocketAppender(LoggerContext context, String customFields,
                                                JHipsterProperties.Logging.Logstash logstashProperties) {
    log.info("Initializing Logstash loggingProperties");

    // More documentation is available at: https://github.com/logstash/logstash-logback-encoder
    LogstashTcpSocketAppender logstashAppender = new LogstashTcpSocketAppender();
    logstashAppender.addDestinations(new InetSocketAddress(logstashProperties.getHost(), logstashProperties.getPort()));
    logstashAppender.setContext(context);
    logstashAppender.setEncoder(logstashEncoder(customFields));
    logstashAppender.setName(ASYNC_LOGSTASH_APPENDER_NAME);
    logstashAppender.setQueueSize(logstashProperties.getQueueSize());
    logstashAppender.start();

    context.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME).addAppender(logstashAppender);
}
 
Example 5
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 6
Source File: LoggingConfiguration.java    From flair-registry 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 7
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 8
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 9
Source File: LoggingConfiguration.java    From TeamDojo 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 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 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 12
Source File: LogstashTcpAppenderFactory.java    From dropwizard-logstash-encoder with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Appender build(LoggerContext context, String s, LayoutFactory layoutFactory,
                      LevelFilterFactory levelFilterFactory,
                      AsyncAppenderFactory asyncAppenderFactory) {
  final LogstashTcpSocketAppender appender = new LogstashTcpSocketAppender();
  final LogstashEncoder encoder = new LogstashEncoder();

  appender.setName("logstash-tcp-appender");
  appender.setContext(context);
  appender.addDestinations(new InetSocketAddress(host, port));
  appender.setIncludeCallerData(includeCallerData);
  appender.setQueueSize(queueSize);

  encoder.setIncludeContext(includeContext);
  encoder.setIncludeMdc(includeMdc);
  encoder.setIncludeCallerData(includeCallerData);

  if (customFields != null) {
    LogstashAppenderFactoryHelper
        .getCustomFieldsFromHashMap(customFields)
        .ifPresent(encoder::setCustomFields);
  }

  if (fieldNames != null) {
    encoder.setFieldNames(LogstashAppenderFactoryHelper.getFieldNamesFromHashMap(fieldNames));
  }

  appender.setEncoder(encoder);
  appender.addFilter(levelFilterFactory.build(threshold));
  encoder.start();
  appender.start();

  return wrapAsync(appender, asyncAppenderFactory);
}
 
Example 13
Source File: LoggingConfiguration.java    From cubeai 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 = "";
    if (consulRegistration != null) {
        optionalFields = "\"instance_id\":\"" + consulRegistration.getInstanceId() + "\",";
    }
    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 14
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 15
Source File: LoggingConfiguration.java    From cubeai 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 = "";
    if (consulRegistration != null) {
        optionalFields = "\"instance_id\":\"" + consulRegistration.getInstanceId() + "\",";
    }
    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 16
Source File: LoggingConfiguration.java    From cubeai 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 = "";
    if (consulRegistration != null) {
        optionalFields = "\"instance_id\":\"" + consulRegistration.getInstanceId() + "\",";
    }
    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 17
Source File: LoggingConfiguration.java    From cubeai 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 = "";
    if (consulRegistration != null) {
        optionalFields = "\"instance_id\":\"" + consulRegistration.getInstanceId() + "\",";
    }
    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 18
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 19
Source File: LoggingConfiguration.java    From cubeai 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 = "";
    if (consulRegistration != null) {
        optionalFields = "\"instance_id\":\"" + consulRegistration.getInstanceId() + "\",";
    }
    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 20
Source File: LoggingConfiguration.java    From java-microservices-examples with Apache License 2.0 5 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);
}