Skip to content
Browse files

upgrade to scalalogging

  • Loading branch information...
1 parent 389fd98 commit 5945373b1f400f530c7740762c600d8b892499af Anders Conbere committed Feb 24, 2013
Showing with 31 additions and 31 deletions.
  1. +18 −12 build.sbt
  2. +9 −15 src/main/scala/Bot.scala
  3. +4 −3 src/main/scala/ExampleBot.scala
  4. +0 −1 src/main/scala/Tokens.scala
View
30 build.sbt
@@ -1,22 +1,32 @@
name := "irc"
+version := "0.1.0"
+
organization := "org.conbere"
-version := "0.1.0"
+licenses := Seq("BSD-style" -> url("http://www.opensource.org/licenses/bsd-license.php"))
+
+homepage := Some(url("http://github.com/aconbere/scala-irc"))
scalaVersion := "2.10.0"
-scalacOptions += "-deprecation"
+scalacOptions ++= Seq(
+ "-deprecation",
+ "-feature"
+)
-scalacOptions += "-feature"
+fork in run := true
resolvers += "Typesafe Repository" at "http://repo.typesafe.com/typesafe/releases/"
-libraryDependencies += "org.scalatest" % "scalatest_2.10" % "1.9.1" % "test"
-
-libraryDependencies += "junit" % "junit" % "4.10" % "test"
-
-libraryDependencies += "com.typesafe.akka" %% "akka-actor" % "2.1.0"
+libraryDependencies ++= Seq(
+ "org.scalatest" % "scalatest_2.10" % "1.9.1" % "test"
+, "junit" % "junit" % "4.10" % "test"
+, "com.typesafe.akka" %% "akka-actor" % "2.1.0"
+, "org.apache.logging.log4j" % "log4j-core" % "2.0-beta3"
+, "com.typesafe" %% "scalalogging-log4j" % "1.0.1"
+, "com.typesafe" % "config" % "1.0.0"
+)
testOptions in Test += Tests.Argument("-oDF")
@@ -33,10 +43,6 @@ publishTo <<= version { (v: String) =>
pomIncludeRepository := { _ => false }
-licenses := Seq("BSD-style" -> url("http://www.opensource.org/licenses/bsd-license.php"))
-
-homepage := Some(url("http://github.com/aconbere/scala-irc"))
-
pomExtra := (
<scm>
<url>git@github.com:aconbere/scala-irc.git</url>
View
24 src/main/scala/Bot.scala
@@ -1,23 +1,22 @@
package org.conbere.irc
+import com.typesafe.scalalogging.log4j.Logging
+
import akka.actor._
import akka.util.{ ByteString, ByteStringBuilder }
import Tokens._
import ControlChars._
import Messages._
-class Bot (
- client:Client,
- rooms:List[Room],
- responder:BotResponder
-) extends Actor {
+class Bot ( client:Client, rooms:List[Room], responder:BotResponder)
+extends Actor with Logging {
val state = IO.IterateeRef.Map.async[IO.Handle]()(context.dispatcher)
def utf8(bytes:ByteString) = bytes.decodeString("UTF-8").trim
override def preStart {
- println("Connecting to " + client.domainName)
+ logger.debug("Connecting to " + client.domainName)
IOManager(context.system).connect(client.address)
}
@@ -26,17 +25,15 @@ class Bot (
case Parser.Success(message, _) =>
Some(message)
case _ =>
- println("Could not parse")
+ logger.error("Could not parse: " + str)
None
}
def readMessage =
for {
in <- IO.takeUntil(CRLF)
} yield {
- val str = utf8(in)
- println("Message: " + str)
- parseMessage(str)
+ parseMessage(utf8(in))
}
def login(socket:IO.SocketHandle) = {
@@ -48,10 +45,8 @@ class Bot (
def respondTo(socket:IO.SocketHandle, message:Message):Unit = {
message match {
case Ping(from) =>
- println("ping from: " + from)
socket.write(Pong(from).toByteString)
case Mode(params) =>
- println("Mode set to: " + params)
socket.write(Join(rooms).toByteString)
case _ =>
// nothin
@@ -66,7 +61,7 @@ class Bot (
def receive = {
case IO.Connected(socket, address) =>
- println("Connected to: " + address)
+ logger.debug("Connected to: " + address)
login(socket)
@@ -78,7 +73,6 @@ class Bot (
for {
message <- ioMessage
} yield {
- println(message)
respondTo(socket, message)
}
}
@@ -89,7 +83,7 @@ class Bot (
state(socket)(IO.Chunk(bytes))
case IO.Closed(socket, cause) =>
- println("Closed")
+ logger.debug("Socket closed")
state(socket)(IO.EOF)
state -= socket
}
View
7 src/main/scala/ExampleBot.scala
@@ -3,15 +3,16 @@ package org.conbere.irc
import Tokens._
import Messages._
import akka.actor._
+import com.typesafe.scalalogging.log4j.Logging
object Main {
- class Responder extends BotResponder {
+ class Responder extends BotResponder with Logging {
def respondTo(message:Message) = message match {
case PrivMsg(to, from, text) =>
- println("PRIVMSG: " + to + ", " + from + " " + text)
+ logger.debug("PRIVMSG: " + to + ", " + from + " " + text)
None
case msg@Message(_, _, _) =>
- println(msg)
+ logger.debug(msg)
None
}
}
View
1 src/main/scala/Tokens.scala
@@ -8,7 +8,6 @@ object Tokens {
sealed trait Token {
def outputString:String
def toByteString() = {
- println("sending: " + outputString)
(new ByteStringBuilder ++= ByteString(outputString) ++= CRLF).result
}
}

0 comments on commit 5945373

Please sign in to comment.
Something went wrong with that request. Please try again.