diff --git a/project/Build.scala b/project/Build.scala index e0c43e8..3212144 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -37,8 +37,7 @@ object Build extends sbt.Build { "org.specs2" %% "specs2-matcher-extra" % specs2Version % "test", "org.specs2" %% "specs2-mock" % specs2Version % "test", "org.scalatest" % "scalatest_2.11" % "2.2.1" % "test", - "org.slf4j" % "slf4j-nop" % slf4jVersion, - "org.slf4j" % "slf4j-api" % slf4jVersion, + "ch.qos.logback" % "logback-classic" % "1.1.2" % "runtime,test", "com.github.scala-incubator.io" %% "scala-io-file" % "0.4.3", "io.strongtyped" %% "active-slick" % "0.3.3", "mysql" % "mysql-connector-java" % "5.1.34", diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml new file mode 100644 index 0000000..6f11e3c --- /dev/null +++ b/src/main/resources/logback.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + ${LOG_FILE_PATH:-log/application-${environment}.log} + true + + ${FILE_LOG_PATTERN} + utf-8 + + + + + ${CONSOLE_LOG_PATTERN} + utf-8 + + + + + + + diff --git a/src/main/scala/com/github/qubo/seed/Boot.scala b/src/main/scala/com/github/qubo/seed/Boot.scala index 74a1298..0939b6e 100644 --- a/src/main/scala/com/github/qubo/seed/Boot.scala +++ b/src/main/scala/com/github/qubo/seed/Boot.scala @@ -7,6 +7,7 @@ import akka.util.Timeout import com.github.qubo.seed.routes.ApiRouterActor import com.github.qubo.seed.utils.Config import Config.App +import org.slf4j.LoggerFactory import spray.can.Http import scala.concurrent.ExecutionContext @@ -14,6 +15,7 @@ import scala.concurrent.duration._ object Boot extends App { + protected val logger = LoggerFactory.getLogger(getClass) // we need an ActorSystem to host our application in implicit val system = ActorSystem(App.systemName) @@ -28,9 +30,9 @@ object Boot extends App { .mapTo[Http.Event] .map { case Http.Bound(address) => - println(s"REST interface bound to $address") + logger.info(s"REST interface bound to $address") case Http.CommandFailed(cmd) => - println("REST interface could not bind to " + s"${App.interface}:${App.port}, ${cmd.failureMessage}") + logger.error(s"REST interface could not bind to ${App.interface}:${App.port}, ${cmd.failureMessage}") system.shutdown() } } \ No newline at end of file diff --git a/src/main/scala/com/github/qubo/seed/routes/ApiRouterActor.scala b/src/main/scala/com/github/qubo/seed/routes/ApiRouterActor.scala index 6ce4d4c..02db643 100644 --- a/src/main/scala/com/github/qubo/seed/routes/ApiRouterActor.scala +++ b/src/main/scala/com/github/qubo/seed/routes/ApiRouterActor.scala @@ -11,6 +11,7 @@ import spray.http.{AllOrigins, StatusCodes} import spray.httpx.SprayJsonSupport import spray.json.DefaultJsonProtocol import spray.routing.{ExceptionHandler, HttpService, Route} +import scalaz._, Scalaz._ import scala.concurrent.ExecutionContext import scala.reflect.runtime.universe.{Type, typeOf} @@ -43,7 +44,13 @@ class ApiRouterActor private def swaggerRoute: Route = (path("swagger.json") & get & complete) { - new SwaggerDefinition(SwaggerDefinitionConfig(types = apiTypes)).prettyJson + new SwaggerDefinition( + SwaggerDefinitionConfig( + types = apiTypes, + host = Config.App.interface, + port = Config.App.port.some + ) + ).prettyJson } private def swaggerUiRoute: Route = diff --git a/src/main/scala/com/github/qubo/seed/swagger/SwaggerDefinition.scala b/src/main/scala/com/github/qubo/seed/swagger/SwaggerDefinition.scala index 5964c74..28d64b1 100644 --- a/src/main/scala/com/github/qubo/seed/swagger/SwaggerDefinition.scala +++ b/src/main/scala/com/github/qubo/seed/swagger/SwaggerDefinition.scala @@ -2,6 +2,7 @@ package com.github.qubo.seed.swagger import java.util +import com.github.qubo.seed.utils.ObjectHelper._ import io.swagger.jaxrs.Reader import io.swagger.jaxrs.config.ReaderConfig import io.swagger.models.Swagger @@ -27,6 +28,7 @@ class SwaggerDefinition(config: SwaggerDefinitionConfig) { lazy val swagger: Swagger = reader.read( config.types .map(getClassNameForType) + .tap(name => logger.info("loading class to swagger: {}", name)) .map(Class.forName).toSet ) diff --git a/src/main/scala/com/github/qubo/seed/utils/Config.scala b/src/main/scala/com/github/qubo/seed/utils/Config.scala index df8b55d..5976e23 100644 --- a/src/main/scala/com/github/qubo/seed/utils/Config.scala +++ b/src/main/scala/com/github/qubo/seed/utils/Config.scala @@ -12,7 +12,7 @@ object Config { private val config = ConfigFactory.parseResources(s"$environment.conf") object App { - val appConf = config.getConfig("app") + private val appConf = config.getConfig("app") val systemName = appConf.getString("systemName") val interface = appConf.getString("interface") val port = appConf.getInt("port") diff --git a/src/main/scala/com/github/qubo/seed/utils/ObjectHelper.scala b/src/main/scala/com/github/qubo/seed/utils/ObjectHelper.scala new file mode 100644 index 0000000..f813a79 --- /dev/null +++ b/src/main/scala/com/github/qubo/seed/utils/ObjectHelper.scala @@ -0,0 +1,11 @@ +package com.github.qubo.seed.utils + +object ObjectHelper { + implicit class RichSeq[+A](seq: Seq[A]) { + def tap(function: A => Unit): Seq[A] = + seq.map { item => + function(item) + item + } + } +}