diff --git a/app/Loader.scala b/app/Loader.scala index b22a459..af9ae91 100644 --- a/app/Loader.scala +++ b/app/Loader.scala @@ -1,4 +1,3 @@ -import story_packages.logging.LogStashConfig import story_packages.metrics.CloudWatchApplicationMetrics import play.api.ApplicationLoader.Context import play.api.{Application, ApplicationLoader, Logger, LoggerConfigurator} @@ -17,7 +16,6 @@ class Loader extends ApplicationLoader { components.actorSystem.scheduler, components.isDev ) - new LogStashConfig(components.config) new SwitchboardLifecycle(SwitchboardConfiguration( objectKey = components.config.switchBoard.objectKey, bucket = components.config.switchBoard.bucket, diff --git a/app/story_packages/logging/LogStash.scala b/app/story_packages/logging/LogStash.scala deleted file mode 100644 index e41f27b..0000000 --- a/app/story_packages/logging/LogStash.scala +++ /dev/null @@ -1,89 +0,0 @@ -package story_packages.logging - -import ch.qos.logback.classic.spi.ILoggingEvent -import ch.qos.logback.classic.{LoggerContext, Logger => LogbackLogger} -import com.amazonaws.auth.STSAssumeRoleSessionCredentialsProvider -import com.gu.logback.appender.kinesis.KinesisAppender -import net.logstash.logback.layout.LogstashLayout -import org.slf4j.LoggerFactory -import play.api.{LoggerLike, Logger} -import conf.ApplicationConfiguration -import story_packages.services.Logging - -object LogStash extends Logging { - - lazy val loggingContext = LoggerFactory.getILoggerFactory.asInstanceOf[LoggerContext] - - case class KinesisAppenderConfig( - stream: String, - region: String, - roleArn: String, - sessionName: String, - bufferSize: Int - ) - - def makeCustomFields(customFields: Map[String, String]): String = { - "{" + (for((k, v) <- customFields) yield(s""""${k}":"${v}"""")).mkString(",") + "}" - } - - def asLogBack(l: LoggerLike): Option[LogbackLogger] = l.logger match { - case l: LogbackLogger => Some(l) - case _ => None - } - - def makeLayout(customFields: String) = { - val l = new LogstashLayout() - l.setCustomFields(customFields) - l - } - - def makeKinesisAppender(layout: LogstashLayout, context: LoggerContext, appenderConfig: KinesisAppenderConfig) = { - val a = new KinesisAppender[ILoggingEvent]() - a.setStreamName(appenderConfig.stream) - a.setRegion(appenderConfig.region) - a.setCredentialsProvider(new STSAssumeRoleSessionCredentialsProvider.Builder( - appenderConfig.roleArn, appenderConfig.sessionName - ).build) - a.setBufferSize(appenderConfig.bufferSize) - - a.setContext(context) - a.setLayout(layout) - - layout.start() - a.start() - a - } - - def init(config: ApplicationConfiguration) = { - if(config.logging.enabled) { - Logger.info("LogConfig initializing") - (for { - lb <- asLogBack(Logger) - } yield { - lb.info("Configuring Logback") - val context = lb.getLoggerContext - val customFields = Map( - "stack" -> "cms-fronts", - "stage" -> config.environment.stage.toUpperCase, - "app" -> config.environment.applicationName - ) - val layout = makeLayout(makeCustomFields(customFields)) - val bufferSize = 1000 - // remove the default configuration - val appender = makeKinesisAppender(layout, context, - KinesisAppenderConfig( - config.logging.stream, - config.logging.streamRegion, - config.logging.streamRole, - config.environment.applicationName, - bufferSize - ) - ) - lb.addAppender(appender) - lb.info("Configured Logback") - })getOrElse(Logger.info("not running using logback")) - } else { - Logger.info("Logging disabled") - } - } -} diff --git a/app/story_packages/logging/LogStashConfig.scala b/app/story_packages/logging/LogStashConfig.scala deleted file mode 100644 index 8130a04..0000000 --- a/app/story_packages/logging/LogStashConfig.scala +++ /dev/null @@ -1,14 +0,0 @@ -package story_packages.logging - -import conf.ApplicationConfiguration -import story_packages.services.Logging - -import scala.util.control.NonFatal - -class LogStashConfig(config: ApplicationConfiguration) extends Logging { - Logger.info("Starting log stash") - try LogStash.init(config) - catch { - case NonFatal(e) => Logger.error("could not configure log stream", e) - } -} diff --git a/build.sbt b/build.sbt index 7acf020..167a656 100644 --- a/build.sbt +++ b/build.sbt @@ -73,7 +73,6 @@ libraryDependencies ++= jacksonOverrides ++ Seq( "com.gu" %% "content-api-models-json" % capiModelsVersion, "com.gu" %% "content-api-client-aws" % "0.7", "com.gu" %% "fapi-client-play28" % "4.0.4", - "com.gu" % "kinesis-logback-appender" % "1.3.0", "com.gu" %% "pan-domain-auth-play_2-8" % "1.3.0", "com.gu" %% "story-packages-model" % "2.2.0", "com.gu" %% "thrift-serializer" % "4.0.0", diff --git a/conf/logback.xml b/conf/logback.xml index 93fc750..c0fca08 100644 --- a/conf/logback.xml +++ b/conf/logback.xml @@ -1,22 +1,30 @@ - story-packages + - logs/story-packages.log + logs/application.log - logs/story-packages.log.%d{yyyy-MM-dd}.gz - 7 + logs/application.log.%d{yyyy-MM-dd}.gz + 2 - %date [%thread] %-5level %logger{36} - %msg%n%xException{3} + %date - [%level] - from %logger in %thread %n%message%n%xException%n + + + + + + + + diff --git a/riff-raff.yaml b/riff-raff.yaml index bce7974..7a48d81 100644 --- a/riff-raff.yaml +++ b/riff-raff.yaml @@ -14,7 +14,7 @@ deployments: prependStackToCloudFormationStackName: false cloudFormationStackName: story-packages amiTags: - Recipe: editorial-tools-focal-java8-ARM + Recipe: editorial-tools-focal-java8-ARM-WITH-cdk-base AmigoStage: PROD amiParameter: MachineImageID