-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #133 from guardian/devx-logs
Use DevX logs instead of kinesis-logback-appender
- Loading branch information
Showing
5 changed files
with
16 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,5 @@ | ||
package com.gu.viewer.logging | ||
|
||
import ch.qos.logback.classic.filter.ThresholdFilter | ||
import ch.qos.logback.classic.{Logger => LogbackLogger} | ||
import ch.qos.logback.classic.spi.ILoggingEvent | ||
import com.amazonaws.auth.InstanceProfileCredentialsProvider | ||
import com.amazonaws.regions.Regions | ||
import com.gu.logback.appender.kinesis.KinesisAppender | ||
import com.gu.viewer.aws.AwsInstanceTags | ||
import com.gu.viewer.config.AppConfig | ||
import net.logstash.logback.layout.LogstashLayout | ||
import org.slf4j.{LoggerFactory, Logger => SLFLogger} | ||
|
||
trait Loggable { | ||
val log = play.api.Logger(getClass) | ||
} | ||
|
||
object LogStash { | ||
private val rootLogger = LoggerFactory.getLogger(SLFLogger.ROOT_LOGGER_NAME).asInstanceOf[LogbackLogger] | ||
|
||
def init(config: AppConfig, tags: AwsInstanceTags, region: Regions): Unit = { | ||
for { | ||
stack <- tags.readTag("Stack") | ||
app <- tags.readTag("App") | ||
stage <- tags.readTag("Stage") | ||
stream <- config.logstashKinesisStream | ||
} { | ||
val context = rootLogger.getLoggerContext | ||
|
||
val layout = new LogstashLayout() | ||
layout.setContext(context) | ||
layout.setCustomFields(s"""{"stack":"$stack","app":"$app","stage":"$stage"}""") | ||
layout.start() | ||
|
||
val filter = new ThresholdFilter() | ||
filter.setLevel("INFO") | ||
filter.start() | ||
|
||
val appender = new KinesisAppender[ILoggingEvent]() | ||
appender.setBufferSize(1000) | ||
appender.setRegion(region.getName) | ||
appender.setStreamName(stream) | ||
appender.setContext(context) | ||
appender.setLayout(layout) | ||
appender.setCredentialsProvider(InstanceProfileCredentialsProvider.getInstance()) | ||
appender.addFilter(filter) | ||
appender.start() | ||
|
||
rootLogger.addAppender(appender) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters