diff --git a/.gitignore b/.gitignore index 83600a3..d164ac8 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ project/target/ *~ .idea .idea_modules +*.iml diff --git a/.travis.yml b/.travis.yml index 771a8bd..5394278 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,8 @@ language: scala scala: - - 2.11.8 - - 2.12.1 + - 2.11.12 + - 2.12.8 + - 2.13.0 sudo: false @@ -14,3 +15,9 @@ before_install: jdk: - oraclejdk8 + +cache: + directories: + - $HOME/.ivy2/cache + - $HOME/.sbt + - $HOME/.coursier diff --git a/build.sbt b/build.sbt index d8aaaf4..6f49004 100644 --- a/build.sbt +++ b/build.sbt @@ -4,16 +4,16 @@ organization := "org.fluentd" name := "fluent-logger-scala" publishMavenStyle := true -scalaVersion := "2.12.1" -crossScalaVersions := Seq("2.11.8", scalaVersion.value) +scalaVersion := "2.12.8" +crossScalaVersions := Seq("2.11.12", scalaVersion.value, "2.13.0") scalacOptions ++= Seq("-deprecation", "-feature", "-language:implicitConversions") logBuffered in Test := false libraryDependencies ++= Seq( - "org.fluentd" % "fluent-logger" % "0.3.2", - "org.json4s" %% "json4s-native" % "3.5.0", + "org.fluentd" % "fluent-logger" % "0.3.4", + "org.json4s" %% "json4s-native" % "3.6.7", "junit" % "junit" % "4.12" % Test, - "org.xerial" %% "fluentd-standalone" % "0.14.11" % Test, - "org.scalatest" %% "scalatest" % "3.0.1" % Test + "org.xerial" %% "fluentd-standalone" % "1.6.2" % Test, + "org.scalatest" %% "scalatest" % "3.0.8" % Test ) // Release settings diff --git a/project/build.properties b/project/build.properties index 27e88aa..c0bab04 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=0.13.13 +sbt.version=1.2.8 diff --git a/project/plugin.sbt b/project/plugin.sbt index d57264e..84fbac4 100755 --- a/project/plugin.sbt +++ b/project/plugin.sbt @@ -1,7 +1,9 @@ -addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.3") -addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "1.1") -addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.0.0") -addSbtPlugin("io.get-coursier" % "sbt-coursier" % "1.0.0-M15") -addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.7.5") +addSbtCoursier + +addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.11") +addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "2.3") +addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.2") +addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.10.0-RC1") +addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.4.2") scalacOptions ++= Seq("-deprecation", "-feature") diff --git a/project/project/plugin.sbt b/project/project/plugin.sbt new file mode 100644 index 0000000..7a05b69 --- /dev/null +++ b/project/project/plugin.sbt @@ -0,0 +1 @@ +addSbtPlugin("io.get-coursier" % "sbt-coursier" % "2.0.0-RC2") diff --git a/src/main/scala/org/fluentd/logger/scala/FluentLogger.scala b/src/main/scala/org/fluentd/logger/scala/FluentLogger.scala index 7fb0736..773e7c3 100644 --- a/src/main/scala/org/fluentd/logger/scala/FluentLogger.scala +++ b/src/main/scala/org/fluentd/logger/scala/FluentLogger.scala @@ -3,7 +3,7 @@ package org.fluentd.logger.scala import org.fluentd.logger.scala.sender.Sender import scala.collection.Map -case class FluentLogger(tag :String, sender: Sender) { +case class FluentLogger(tag: String, sender: Sender) { def log(label: String, key: String, value: Any): Boolean = { log(label, key, value, 0) @@ -41,7 +41,7 @@ case class FluentLogger(tag :String, sender: Sender) { def getName: String = sender.getName() - override def toString: String = sender.toString() + override def toString: String = sender.toString override def finalize(): Unit = sender.close() diff --git a/src/main/scala/org/fluentd/logger/scala/FluentLoggerFactory.scala b/src/main/scala/org/fluentd/logger/scala/FluentLoggerFactory.scala index 6361e29..51bef89 100644 --- a/src/main/scala/org/fluentd/logger/scala/FluentLoggerFactory.scala +++ b/src/main/scala/org/fluentd/logger/scala/FluentLoggerFactory.scala @@ -25,7 +25,6 @@ object FluentLoggerFactory { val senderPropertyName = JavaConstants.FLUENT_SENDER_CLASS val scalaSenderName = "ScalaRawSocketSender" val senderClassName = System.getProperty(senderPropertyName, scalaSenderName) - val factory = new FluentLoggerFactory() val loggers: WeakHashMap[String, FluentLogger] = new WeakHashMap def getLogger(tag: String): FluentLogger = { @@ -39,7 +38,7 @@ object FluentLoggerFactory { def getLogger(tag: String, host: String, port: Int, timeout: Int, bufferCapacity: Int): FluentLogger = { val sender = new ScalaRawSocketSender(host, port, timeout, bufferCapacity) - val logger = new FluentLogger(tag, sender) + val logger = FluentLogger(tag, sender) loggers.put(tag, logger) logger } @@ -55,9 +54,4 @@ object FluentLoggerFactory { logger.close() } } - -} - -class FluentLoggerFactory { - } diff --git a/src/main/scala/org/fluentd/logger/scala/sender/EventSerializer.scala b/src/main/scala/org/fluentd/logger/scala/sender/EventSerializer.scala index 1bd528c..33928be 100644 --- a/src/main/scala/org/fluentd/logger/scala/sender/EventSerializer.scala +++ b/src/main/scala/org/fluentd/logger/scala/sender/EventSerializer.scala @@ -15,9 +15,9 @@ object EventSerializer extends Serializer[Event] { def deserialize(implicit format: Formats): PartialFunction[(TypeInfo, JValue), Event] = { case (TypeInfo(EventClass, _), json) => json match { case JArray(JString(tag) :: JInt(time) :: JObject(obj) :: Nil) => - new Event(tag, time.toLong, null) + Event(tag, time.toLong, null) case JNothing => - new Event(null, 0, null) + Event(null, 0, null) case x => throw new MappingException(s"Can't convert $x to Event") } } diff --git a/src/main/scala/org/fluentd/logger/scala/sender/MapSerializer.scala b/src/main/scala/org/fluentd/logger/scala/sender/MapSerializer.scala index 9e81ffa..a4d4c96 100644 --- a/src/main/scala/org/fluentd/logger/scala/sender/MapSerializer.scala +++ b/src/main/scala/org/fluentd/logger/scala/sender/MapSerializer.scala @@ -16,7 +16,7 @@ object MapSerializer extends Serializer[Map[String, Any]] { }, Extraction.decompose( v match { - case vs: MutableMap[_,_] => vs.toMap + case vs: MutableMap[_, _] => vs.toMap case _ => v } ) diff --git a/src/main/scala/org/fluentd/logger/scala/sender/ScalaRawSocketSender.scala b/src/main/scala/org/fluentd/logger/scala/sender/ScalaRawSocketSender.scala index f32e941..04a3d3e 100644 --- a/src/main/scala/org/fluentd/logger/scala/sender/ScalaRawSocketSender.scala +++ b/src/main/scala/org/fluentd/logger/scala/sender/ScalaRawSocketSender.scala @@ -8,20 +8,20 @@ import org.json4s._ import org.json4s.native.Serialization import scala.collection.Map -class ScalaRawSocketSender(h:String, p:Int, to:Int, bufCap:Int) +class ScalaRawSocketSender(h: String, p: Int, to: Int, bufCap: Int) extends Sender { - implicit val formats = DefaultFormats + EventSerializer + MapSerializer + implicit val formats: Formats = DefaultFormats + EventSerializer + MapSerializer val LOG = java.util.logging.Logger.getLogger("ScalaRawSocketSender") val host = h val port = p - val bufferCapacity= bufCap + val bufferCapacity = bufCap val timeout = to val name = "%s_%d_%d_%d".format(host, port, timeout, bufferCapacity) val pendings = ByteBuffer.allocate(bufferCapacity) val server = new InetSocketAddress(host, port) val reconnector = new ExponentialDelayReconnector() - var socket:Socket = null - var out:BufferedOutputStream = null + var socket: Socket = null + var out: BufferedOutputStream = null open() def this(host:String, port:Int) { @@ -96,7 +96,7 @@ class ScalaRawSocketSender(h:String, p:Int, to:Int, bufCap:Int) } def emit(tag: String, timestamp: Long, data: Map[String, Any]): Boolean = { - emit(new Event(tag, timestamp, data)) + emit(Event(tag, timestamp, data)) } def emit(event: Event): Boolean = { @@ -107,7 +107,7 @@ class ScalaRawSocketSender(h:String, p:Int, to:Int, bufCap:Int) try { // serialize tag, timestamp and data val json = Serialization.write(event) - return send(json.getBytes("UTF-8")) + send(json.getBytes("UTF-8")) } catch { case e: IOException => LOG.severe(s"Cannot serialize event: $event") @@ -155,14 +155,14 @@ class ScalaRawSocketSender(h:String, p:Int, to:Int, bufCap:Int) clearBuffer() } catch { case e: IOException => - LOG.throwing(this.getClass().getName(), "flush", e) + LOG.throwing(this.getClass.getName, "flush", e) reconnector.addErrorHistory(System.currentTimeMillis()) } } def getName(): String = name - override def toString(): String = { + override def toString: String = { getName() } } diff --git a/src/main/scala/org/fluentd/logger/scala/sender/Sender.scala b/src/main/scala/org/fluentd/logger/scala/sender/Sender.scala index 1e8915d..36fb940 100644 --- a/src/main/scala/org/fluentd/logger/scala/sender/Sender.scala +++ b/src/main/scala/org/fluentd/logger/scala/sender/Sender.scala @@ -7,11 +7,11 @@ trait Sender { def emit(tag: String, timestamp: Long, data: Map[String, Any]): Boolean - def flush() + def flush(): Unit def getBuffer(): Array[Byte] - def close() + def close(): Unit def getName(): String } diff --git a/src/test/java/org/fluentd/logger/util/MockFluentd.java b/src/test/java/org/fluentd/logger/util/MockFluentd.java deleted file mode 100644 index 6625972..0000000 --- a/src/test/java/org/fluentd/logger/util/MockFluentd.java +++ /dev/null @@ -1,132 +0,0 @@ -// -// A Structured Logger for Fluent -// -// Copyright (C) 2011 - 2012 Muga NISHIZAWA -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -package org.fluentd.logger.util; - -import java.io.IOException; -import java.net.ServerSocket; -import java.net.Socket; -import java.util.HashMap; -import java.util.concurrent.atomic.AtomicBoolean; - -import org.fluentd.logger.sender.Event; -import org.msgpack.MessagePack; -import org.msgpack.packer.Packer; -import org.msgpack.template.Templates; -import org.msgpack.type.Value; -import org.msgpack.unpacker.Unpacker; - -public class MockFluentd extends Thread { - - public static interface MockProcess { - public void process(MessagePack msgpack, Socket socket) throws IOException; - } - - public static class MockEventTemplate extends Event.EventTemplate { - public static MockEventTemplate INSTANCE = new MockEventTemplate(); - - public void write(Packer pk, Event v, boolean required) throws IOException { - throw new UnsupportedOperationException("don't need operation"); - } - - public Event read(Unpacker u, Event to, boolean required) throws IOException { - if (!required && u.trySkipNil()) { - return null; - } - - to = new Event(); - u.readArrayBegin(); - { - to.tag = Templates.TString.read(u, null, required); - to.timestamp = Templates.TLong.read(u, null, required); - int size = u.readMapBegin(); - to.data = new HashMap(size); - { - for (int i = 0; i < size; i++) { - String key = (String) toObject(u, u.readValue()); - Object value = toObject(u, u.readValue()); - to.data.put(key, value); - } - } - u.readMapEnd(); - } - u.readArrayEnd(); - return to; - } - - private static Object toObject(Unpacker u, Value v) { - if (v.isNilValue()) { - v.asNilValue(); - return null; - } else if (v.isRawValue()) { - return v.asRawValue().getString(); // String only - } else if (v.isBooleanValue()) { - return v.asBooleanValue().getBoolean(); - } else if (v.isFloatValue()) { - return v.asFloatValue().getDouble(); // double only - } else if (v.isIntegerValue()) { - return v.asIntegerValue().getLong(); // long only - } else if (v.isMapValue()) { - throw new UnsupportedOperationException(); - } else if (v.isArrayValue()) { - throw new UnsupportedOperationException(); - } else { - throw new UnsupportedOperationException(); - } - } - } - - private ServerSocket serverSocket; - - private MockProcess process; - - private AtomicBoolean finished = new AtomicBoolean(false); - - public MockFluentd(int port, MockProcess mockProcess) throws IOException { - serverSocket = new ServerSocket(port); - process = mockProcess; - } - - public void run() { - while (!finished.get()) { - try { - final Socket socket = serverSocket.accept(); - Runnable r = new Runnable() { - public void run() { - try { - MessagePack msgpack = new MessagePack(); - msgpack.register(Event.class, MockEventTemplate.INSTANCE); - process.process(msgpack, socket); - } catch (IOException e) { - // ignore - } - } - }; - new Thread(r).start(); - } catch (IOException e) { - // ignore - } - } - } - - public void close() throws IOException { - finished.set(true); - if (serverSocket != null) { - serverSocket.close(); - } - } -} diff --git a/src/test/scala/org/fluentd/logger/scala/FluentLoggerSuite.scala b/src/test/scala/org/fluentd/logger/scala/FluentLoggerSuite.scala index e03799e..f63654e 100644 --- a/src/test/scala/org/fluentd/logger/scala/FluentLoggerSuite.scala +++ b/src/test/scala/org/fluentd/logger/scala/FluentLoggerSuite.scala @@ -22,7 +22,7 @@ import org.junit.runner.RunWith import org.json4s.NoTypeHints import org.json4s.native.Serialization import org.scalatest.{BeforeAndAfterAll, Tag, FunSuite} -import org.scalatest.junit.JUnitRunner +import org.scalatestplus.junit.JUnitRunner import scala.collection.mutable.HashMap import xerial.fluentd.FluentdStandalone @@ -36,7 +36,6 @@ class FluentLoggerSuite extends FunSuite with BeforeAndAfterAll { override def beforeAll(): Unit = { // Start local fluentd server fluentd = Some(FluentdStandalone.start()) - val port = fluentd.get.port logger = fluentd.map(fd => FluentLoggerFactory.getLogger("debug", "localhost", fd.port)).getOrElse { fail("Failed to start fluentd") } diff --git a/src/test/scala/org/fluentd/logger/scala/util/Verifier.scala b/src/test/scala/org/fluentd/logger/scala/util/Verifier.scala deleted file mode 100644 index af76fa8..0000000 --- a/src/test/scala/org/fluentd/logger/scala/util/Verifier.scala +++ /dev/null @@ -1,7 +0,0 @@ -package org.fluentd.logger.scala.util - -import org.fluentd.logger.scala.sender.Event - -trait Verifier { - def verify(event: Event) -}