@Test
 public void patternIncludesAppNameAndPid() throws Exception {
   final AsyncAppender wrapper =
       (AsyncAppender)
           new SyslogAppenderFactory()
               .build(
                   new LoggerContext(),
                   "MyApplication",
                   new DropwizardLayoutFactory(),
                   new NullLevelFilterFactory<>(),
                   new AsyncLoggingEventAppenderFactory());
   assertThat(((SyslogAppender) wrapper.getAppender("syslog-appender")).getSuffixPattern())
       .matches("^MyApplication\\[\\d+\\].+");
 }
 @Test
 public void stackTracePatternCanBeSet() throws Exception {
   final SyslogAppenderFactory syslogAppenderFactory = new SyslogAppenderFactory();
   syslogAppenderFactory.setStackTracePrefix("--->");
   final AsyncAppender wrapper =
       (AsyncAppender)
           syslogAppenderFactory.build(
               new LoggerContext(),
               "MyApplication",
               new DropwizardLayoutFactory(),
               new NullLevelFilterFactory<>(),
               new AsyncLoggingEventAppenderFactory());
   assertThat(((SyslogAppender) wrapper.getAppender("syslog-appender")).getStackTracePattern())
       .isEqualTo("--->");
 }
Пример #3
0
  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);
  }