Search in sources :

Example 1 with GelfAppender

use of de.appelgriepsch.logback.GelfAppender in project coffeenet-starter by coffeenet.

the class CoffeeNetLoggingAutoConfigurationTest method integration.

@Test
public void integration() {
    final Logger logger = (Logger) LoggerFactory.getLogger(ROOT_LOGGER_NAME);
    assertThat(logger.getAppender("CONSOLE"), is(instanceOf(ConsoleAppender.class)));
    Appender<ILoggingEvent> fileAppender = logger.getAppender("COFFEENET-FILE");
    assertThat(fileAppender, is(instanceOf(RollingFileAppender.class)));
    // Check File Appender
    RollingFileAppender rollingFileAppender = (RollingFileAppender) fileAppender;
    assertThat(rollingFileAppender.getFile(), is("logs/app.log"));
    assertThat(rollingFileAppender.getName(), is("COFFEENET-FILE"));
    RollingPolicy rollingPolicy = rollingFileAppender.getRollingPolicy();
    assertThat(rollingPolicy, is(instanceOf(TimeBasedRollingPolicy.class)));
    TimeBasedRollingPolicy timeBasedRollingPolicy = (TimeBasedRollingPolicy) rollingFileAppender.getRollingPolicy();
    assertThat(timeBasedRollingPolicy.getFileNamePattern(), is("logs/app-%d{yyyy-MM-dd}.log"));
    PatternLayoutEncoder encoder = (PatternLayoutEncoder) rollingFileAppender.getEncoder();
    assertThat(encoder.getPattern(), is("%d{yyyy-MM-dd HH:mm:ss.SSS} %5p --- [%t] %-40.40logger{39} : %m%n%wEx"));
    // Check Gelf Appender
    Appender<ILoggingEvent> gelfAppender = logger.getAppender("COFFEENET-GELF");
    assertThat(gelfAppender, is(instanceOf(GelfAppender.class)));
    GelfAppender gelfAppender1 = (GelfAppender) gelfAppender;
    assertThat(gelfAppender1.getName(), is("COFFEENET-GELF"));
    assertThat(gelfAppender1.getServer(), is("localServer"));
    assertThat(gelfAppender1.getProtocol(), is("TCP"));
    assertThat(gelfAppender1.getPort(), is(1337));
    assertThat(((PatternLayout) gelfAppender1.getLayout()).getPattern(), is("%m"));
    assertThat(gelfAppender1.getAdditionalFields(), hasEntry("environment", "test"));
    assertThat(gelfAppender1.getAdditionalFields(), hasEntry("application", "CoffeeNetApplication"));
}
Also used : PatternLayoutEncoder(ch.qos.logback.classic.encoder.PatternLayoutEncoder) RollingFileAppender(ch.qos.logback.core.rolling.RollingFileAppender) GelfAppender(de.appelgriepsch.logback.GelfAppender) RollingPolicy(ch.qos.logback.core.rolling.RollingPolicy) TimeBasedRollingPolicy(ch.qos.logback.core.rolling.TimeBasedRollingPolicy) Logger(ch.qos.logback.classic.Logger) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) TimeBasedRollingPolicy(ch.qos.logback.core.rolling.TimeBasedRollingPolicy) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with GelfAppender

use of de.appelgriepsch.logback.GelfAppender in project coffeenet-starter by coffeenet.

the class CoffeeNetLoggingAutoConfiguration method gelfAppender.

private GelfAppender gelfAppender(LoggerContext loggerContext) {
    GelfAppender gelfAppender = new GelfAppender();
    gelfAppender.setContext(loggerContext);
    gelfAppender.setName(COFFEENET_GELF);
    gelfAppender.setServer(coffeeNetLoggingGelfProperties.getServer());
    gelfAppender.setProtocol(coffeeNetLoggingGelfProperties.getProtocol());
    gelfAppender.setPort(coffeeNetLoggingGelfProperties.getPort());
    gelfAppender.addAdditionalField("application", coffeeNetConfigurationProperties.getApplicationName());
    gelfAppender.addAdditionalField("environment", coffeeNetLoggingGelfProperties.getEnvironment());
    PatternLayout patternLayout = new PatternLayout();
    patternLayout.setContext(loggerContext);
    patternLayout.setPattern(coffeeNetLoggingGelfProperties.getLayout());
    patternLayout.start();
    gelfAppender.setLayout(patternLayout);
    gelfAppender.start();
    return gelfAppender;
}
Also used : PatternLayout(ch.qos.logback.classic.PatternLayout) GelfAppender(de.appelgriepsch.logback.GelfAppender)

Example 3 with GelfAppender

use of de.appelgriepsch.logback.GelfAppender in project coffeenet-starter by coffeenet.

the class CoffeeNetLoggingAutoConfigurationTest method integration.

@Test
public void integration() {
    final Logger logger = (Logger) LoggerFactory.getLogger(ROOT_LOGGER_NAME);
    assertThat(logger.getAppender("CONSOLE"), is(instanceOf(ConsoleAppender.class)));
    Appender<ILoggingEvent> fileAppender = logger.getAppender("COFFEENET-FILE");
    assertThat(fileAppender, is(instanceOf(RollingFileAppender.class)));
    // Check File Appender
    RollingFileAppender rollingFileAppender = (RollingFileAppender) fileAppender;
    assertThat(rollingFileAppender.getFile(), is("logs/app.log"));
    assertThat(rollingFileAppender.getName(), is("COFFEENET-FILE"));
    RollingPolicy rollingPolicy = rollingFileAppender.getRollingPolicy();
    assertThat(rollingPolicy, is(instanceOf(TimeBasedRollingPolicy.class)));
    TimeBasedRollingPolicy timeBasedRollingPolicy = (TimeBasedRollingPolicy) rollingFileAppender.getRollingPolicy();
    assertThat(timeBasedRollingPolicy.getFileNamePattern(), is("logs/app-%d{yyyy-MM-dd}.log"));
    PatternLayoutEncoder encoder = (PatternLayoutEncoder) rollingFileAppender.getEncoder();
    assertThat(encoder.getPattern(), is("%d{yyyy-MM-dd HH:mm:ss.SSS} %5p --- [%t] %-40.40logger{39} : %m%n%wEx"));
    // Check Gelf Appender
    Appender<ILoggingEvent> gelfAppender = logger.getAppender("COFFEENET-GELF");
    assertThat(gelfAppender, is(instanceOf(GelfAppender.class)));
    GelfAppender gelfAppender1 = (GelfAppender) gelfAppender;
    assertThat(gelfAppender1.getName(), is("COFFEENET-GELF"));
    assertThat(gelfAppender1.getServer(), is("localServer"));
    assertThat(gelfAppender1.getProtocol(), is("TCP"));
    assertThat(gelfAppender1.getPort(), is(1337));
    assertThat(((PatternLayout) gelfAppender1.getLayout()).getPattern(), is("%m"));
    assertThat(gelfAppender1.getAdditionalFields(), hasEntry("environment", "test"));
    assertThat(gelfAppender1.getAdditionalFields(), hasEntry("application", "CoffeeNetApplication"));
}
Also used : PatternLayoutEncoder(ch.qos.logback.classic.encoder.PatternLayoutEncoder) RollingFileAppender(ch.qos.logback.core.rolling.RollingFileAppender) GelfAppender(de.appelgriepsch.logback.GelfAppender) RollingPolicy(ch.qos.logback.core.rolling.RollingPolicy) TimeBasedRollingPolicy(ch.qos.logback.core.rolling.TimeBasedRollingPolicy) Logger(ch.qos.logback.classic.Logger) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) TimeBasedRollingPolicy(ch.qos.logback.core.rolling.TimeBasedRollingPolicy) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with GelfAppender

use of de.appelgriepsch.logback.GelfAppender in project coffeenet-starter by coffeenet.

the class CoffeeNetLoggingAutoConfiguration method gelfAppender.

private GelfAppender gelfAppender(LoggerContext loggerContext) {
    GelfAppender gelfAppender = new GelfAppender();
    gelfAppender.setContext(loggerContext);
    gelfAppender.setName(COFFEENET_GELF);
    gelfAppender.setServer(coffeeNetLoggingGelfProperties.getServer());
    gelfAppender.setProtocol(coffeeNetLoggingGelfProperties.getProtocol());
    gelfAppender.setPort(coffeeNetLoggingGelfProperties.getPort());
    gelfAppender.addAdditionalField("application", coffeeNetConfigurationProperties.getApplicationName());
    gelfAppender.addAdditionalField("environment", coffeeNetLoggingGelfProperties.getEnvironment());
    PatternLayout patternLayout = new PatternLayout();
    patternLayout.setContext(loggerContext);
    patternLayout.setPattern(coffeeNetLoggingGelfProperties.getLayout());
    patternLayout.start();
    gelfAppender.setLayout(patternLayout);
    gelfAppender.start();
    return gelfAppender;
}
Also used : PatternLayout(ch.qos.logback.classic.PatternLayout) GelfAppender(de.appelgriepsch.logback.GelfAppender)

Aggregations

GelfAppender (de.appelgriepsch.logback.GelfAppender)4 Logger (ch.qos.logback.classic.Logger)2 PatternLayout (ch.qos.logback.classic.PatternLayout)2 PatternLayoutEncoder (ch.qos.logback.classic.encoder.PatternLayoutEncoder)2 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)2 RollingFileAppender (ch.qos.logback.core.rolling.RollingFileAppender)2 RollingPolicy (ch.qos.logback.core.rolling.RollingPolicy)2 TimeBasedRollingPolicy (ch.qos.logback.core.rolling.TimeBasedRollingPolicy)2 Test (org.junit.Test)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2