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"));
}
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;
}
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"));
}
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;
}
Aggregations