Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement logging with Log4j2 for aws-scala-sbt #6078

Merged
merged 3 commits into from May 6, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -1,17 +1,19 @@
import sbt.Keys._ import sbtassembly.Log4j2MergeStrategy
import sbt._
import sbtrelease.Version import sbtrelease.Version


name := "hello" name := "hello"


resolvers += Resolver.sonatypeRepo("public") resolvers += Resolver.sonatypeRepo("public")
scalaVersion := "2.12.8" scalaVersion := "2.12.8"
releaseNextVersion := { ver => Version(ver).map(_.bumpMinor.string).getOrElse("Error") } releaseNextVersion := { ver =>
Version(ver).map(_.bumpMinor.string).getOrElse("Error")
}
assemblyJarName in assembly := "hello.jar" assemblyJarName in assembly := "hello.jar"


libraryDependencies ++= Seq( libraryDependencies ++= Seq(
"com.amazonaws" % "aws-lambda-java-events" % "2.2.5", "com.amazonaws" % "aws-lambda-java-events" % "2.2.6",
"com.amazonaws" % "aws-lambda-java-core" % "1.2.0" "com.amazonaws" % "aws-lambda-java-core" % "1.2.0",
"com.amazonaws" % "aws-lambda-java-log4j2" % "1.1.0"
) )


scalacOptions ++= Seq( scalacOptions ++= Seq(
@@ -20,3 +22,11 @@ scalacOptions ++= Seq(
"-feature", "-feature",
"-Xfatal-warnings" "-Xfatal-warnings"
) )

assemblyMergeStrategy in assembly := {
case PathList(ps @ _*) if ps.last == "Log4j2Plugins.dat" =>
Log4j2MergeStrategy.plugincache
case x =>
val oldStrategy = (assemblyMergeStrategy in assembly).value
oldStrategy(x)
}
@@ -1,4 +1,3 @@
resolvers += Resolver.sonatypeRepo("public")

addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.9") addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.9")
addSbtPlugin("com.github.nomadblacky" % "sbt-assembly-log4j2" % "0.1.1")

This comment has been minimized.

Copy link
@NomadBlacky

NomadBlacky May 4, 2019

Author Contributor

A sbt-plugin has been released that merges Log4j2Plugins.dat.

However, it doesn't support sbt 1.x.
I released a fork that supports sbt 1.x.

addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.11") addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.11")
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration packages="com.amazonaws.services.lambda.runtime.log4j2">
<Appenders>
<Lambda name="Lambda">
<PatternLayout>
<pattern>%d{yyyy-MM-dd HH:mm:ss} %X{AWSRequestId} %-5p %c{1}:%L - %m%n</pattern>
</PatternLayout>
</Lambda>
</Appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="Lambda" />
</Root>
</Loggers>
</Configuration>
@@ -1,11 +1,16 @@
package hello package hello


import com.amazonaws.services.lambda.runtime.{Context, RequestHandler} import com.amazonaws.services.lambda.runtime.{Context, RequestHandler}
import org.apache.logging.log4j.{LogManager, Logger}

import scala.collection.JavaConverters import scala.collection.JavaConverters


class Handler extends RequestHandler[Request, Response] { class Handler extends RequestHandler[Request, Response] {


val logger: Logger = LogManager.getLogger(getClass)

def handleRequest(input: Request, context: Context): Response = { def handleRequest(input: Request, context: Context): Response = {
logger.info(s"Received a request: $input")
Response("Go Serverless v1.0! Your function executed successfully!", input) Response("Go Serverless v1.0! Your function executed successfully!", input)
} }
} }
@@ -4,4 +4,6 @@ import scala.beans.BeanProperty


class Request(@BeanProperty var key1: String, @BeanProperty var key2: String, @BeanProperty var key3: String) { class Request(@BeanProperty var key1: String, @BeanProperty var key2: String, @BeanProperty var key3: String) {
def this() = this("", "", "") def this() = this("", "", "")

override def toString: String = s"Request($key1, $key2, $key3)"
} }
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.