Skip to content

Instantly share code, notes, and snippets.

@monkey-codes
monkey-codes / gist:d2908935000c754c6b87aeecb176b069
Created August 8, 2016 04:39
Gradle dependencies to setup logstash logback
dependencies {
ext {
logbackVersion = '1.1.6'
slf4jApiVersion = '1.7.15'
logStashLogbackEncoderVersion = '4.7'
}
...
compile("ch.qos.logback:logback-classic:$logbackVersion")
compile("ch.qos.logback:logback-core:$logbackVersion")
compile("ch.qos.logback:logback-access:$logbackVersion")
dependencies {
ext {
logbackVersion = '1.1.6'
slf4jApiVersion = '1.7.15'
logStashLogbackEncoderVersion = '4.7'
}
compile("ch.qos.logback:logback-classic:$logbackVersion")
compile("ch.qos.logback:logback-core:$logbackVersion")
compile("ch.qos.logback:logback-access:$logbackVersion")
{
"@timestamp":"2016-07-21T14:00:10.389+1000",
"@version":1,
"message":"Started CloudwatchLoggingApplication in 1.97 seconds (JVM running for 3.463)",
"logger_name":"c.m.l.CloudwatchLoggingApplication",
"thread_name":"main",
"level":"INFO",
"level_value":20000
}
import ch.qos.logback.core.ConsoleAppender
import codes.monkey.logging.BeanStalkPropertyDefiner
import codes.monkey.logging.LoggingTagsPropertyDefiner
import net.logstash.logback.appender.LoggingEventAsyncDisruptorAppender
import net.logstash.logback.stacktrace.ShortenedThrowableConverter
import codes.monkey.logging.TimestampFormatPropertyDefiner.CloudwatchLogstashEncoder
import groovy.json.JsonOutput
{
"@timestamp":"2016-07-27T10:15:02.606+1000",
"@version":1,
"@message":"0:0:0:0:0:0:0:1 - - [2016-07-27T10:15:02.606+10:00] \"GET /favicon.ico HTTP/1.1\" 200 946",
"fields_method":"GET",
"fields_protocol":"HTTP/1.1",
"fields_status_code":200,
"fields_requested_url":"GET /favicon.ico HTTP/1.1",
"fields_requested_uri":"/favicon.ico",
"fields_remote_host":"0:0:0:0:0:0:0:1",
@SpringBootApplication
class CloudwatchLoggingApplication {
@Bean
EmbeddedServletContainerFactory servletContainer(TomcatContextCustomizer customizer) {
def factory = new TomcatEmbeddedServletContainerFactory()
factory.setTomcatContextCustomizers([customizer])
factory
}
<configuration>
<define name="app_name" class="codes.monkey.logging.LoggingTagsPropertyDefiner">
<property>app.name</property>
</define>
<define name="app_version" class="codes.monkey.logging.LoggingTagsPropertyDefiner">
<property>app.version</property>
</define>
<define name="eb_hostname" class="codes.monkey.logging.BeanStalkPropertyDefiner">
<field>hostname</field>
</define>
Mappings:
CWLogs:
WebRequestLogGroup:
TimestampFormat: "%Y-%m-%dT%H:%M:%S.%f%z"
Outputs:
WebRequestCWLogGroup:
Description: "The name of the Cloudwatch Logs Log Group created for this environments web server access logs. You can specify this by setting the value for the environment variable: WebRequestCWLogGroup. Please note: if you update this value, then you will need to go and clear out the old cloudwatch logs group and delete it through Cloudwatch Logs."
Value: { "Ref" : "AWSEBCloudWatchLogsAppLogGroup"}
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents",
"logs:DescribeLogStreams",
appender('perf-summary', LogstashAsyncCoalescingStatisticsAppender) {
timeSlice = 30000
queueSize = 30000
createRollupStatistics = false
appender(LoggingEventAsyncDisruptorAppender) {
appender(ConsoleAppender) {
encoder(CloudwatchLogstashEncoder) {
customFields = loggingMarkers
shortenedLoggerNameLength = 36
}