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

support for scala 2.13. #37

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ project/target/
*~
.idea
.idea_modules
*.iml
13 changes: 10 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
language: scala
scala:
- 2.11.8
- 2.12.1
- 2.11.12
- 2.12.8
- 2.13.0

sudo: false

Expand All @@ -10,7 +11,13 @@ script: sbt ++$TRAVIS_SCALA_VERSION test
before_install:
- rvm install 2.2.0
- rvm use 2.2.0
- gem install fluentd -v 0.14.11
- gem install fluentd -v 1.6.2

jdk:
- oraclejdk8

cache:
directories:
- $HOME/.ivy2/cache
- $HOME/.sbt
- $HOME/.coursier
12 changes: 6 additions & 6 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=0.13.13
sbt.version=1.2.8
12 changes: 7 additions & 5 deletions project/plugin.sbt
Original file line number Diff line number Diff line change
@@ -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")
1 change: 1 addition & 0 deletions project/project/plugin.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
addSbtPlugin("io.get-coursier" % "sbt-coursier" % "2.0.0-RC2")
4 changes: 2 additions & 2 deletions src/main/scala/org/fluentd/logger/scala/FluentLogger.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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
}
Expand All @@ -55,9 +54,4 @@ object FluentLoggerFactory {
logger.close()
}
}

}

class FluentLoggerFactory {

}
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 = {
Expand All @@ -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")
Expand Down Expand Up @@ -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()
}
}
4 changes: 2 additions & 2 deletions src/main/scala/org/fluentd/logger/scala/sender/Sender.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
132 changes: 0 additions & 132 deletions src/test/java/org/fluentd/logger/util/MockFluentd.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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")
}
Expand Down
7 changes: 0 additions & 7 deletions src/test/scala/org/fluentd/logger/scala/util/Verifier.scala

This file was deleted.