-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2d79738
commit c67621d
Showing
5 changed files
with
112 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
rapid/shared/src/main/scala/scribe/rapid/RapidLoggerSupport.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package scribe.rapid | ||
|
||
import _root_.rapid.Task | ||
import scribe.mdc.MDC | ||
import scribe.{Level, LogFeature, LogRecord, Logger, LoggerSupport} | ||
import sourcecode.{FileName, Line, Name, Pkg} | ||
|
||
trait RapidLoggerSupport extends Any with LoggerSupport[Task[Unit]] { | ||
override def log(record: LogRecord): Task[Unit] = Task(Logger(record.className).log(record)) | ||
|
||
override def log(level: Level, mdc: MDC, features: LogFeature*) | ||
(implicit pkg: Pkg, fileName: FileName, name: Name, line: Line): Task[Unit] = | ||
log(LoggerSupport(level, Nil, pkg, fileName, name, line, mdc).withFeatures(features: _*)) | ||
} |
14 changes: 14 additions & 0 deletions
14
rapid/shared/src/main/scala/scribe/rapid/RapidLoggerWrapper.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package scribe.rapid | ||
|
||
import _root_.rapid.Task | ||
import scribe.{Level, LogFeature, LogRecord, Logger} | ||
import scribe.mdc.MDC | ||
import sourcecode.{FileName, Line, Name, Pkg} | ||
|
||
class RapidLoggerWrapper(val wrapped: Logger) extends AnyVal with RapidLoggerSupport { | ||
override def log(record: LogRecord): Task[Unit] = Task(wrapped.log(record)) | ||
|
||
override def log(level: Level, mdc: MDC, features: LogFeature*) | ||
(implicit pkg: Pkg, fileName: FileName, name: Name, line: Line): Task[Unit] = | ||
Task(wrapped.log(level, mdc, features: _*)(pkg, fileName, name, line)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package scribe | ||
|
||
package object rapid extends RapidLoggerSupport { | ||
implicit class LoggerExtras(val logger: Logger) extends AnyVal { | ||
def rapid: RapidLoggerSupport = new RapidLoggerWrapper(logger) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package spec | ||
|
||
import org.scalatest.matchers.should.Matchers | ||
import org.scalatest.wordspec.AnyWordSpec | ||
import rapid.Task | ||
import scribe.handler.LogHandler | ||
import scribe.rapid._ | ||
import scribe.{LogRecord, Logger} | ||
import scribe.{rapid => logger} | ||
|
||
class ScribeRapidSpec extends AnyWordSpec with Matchers { | ||
"ScribeEffect" should { | ||
var messages: List[String] = Nil | ||
Logger.root | ||
.clearHandlers() | ||
.withHandler(new LogHandler { | ||
override def log(record: LogRecord): Unit = synchronized { | ||
messages = record.messages.map(_.logOutput.plainText) ::: messages | ||
} | ||
}) | ||
.replace() | ||
|
||
"do rapid logging" in { | ||
logger.info("1").map { _ => | ||
messages should be(List("1")) | ||
}.sync() | ||
} | ||
"do instantiation logging" in { | ||
messages = Nil | ||
|
||
val biz = new Biz | ||
biz.doStuff().map { s => | ||
messages should be(List("3")) | ||
s should be("done") | ||
}.sync() | ||
} | ||
"do reference logging" in { | ||
messages = Nil | ||
|
||
logger.info("4").map { _ => | ||
messages should be(List("4")) | ||
}.sync() | ||
} | ||
"do existing logger logging" in { | ||
messages = Nil | ||
Logger.root.rapid.info("5").map { _ => | ||
messages should be(List("5")) | ||
}.sync() | ||
} | ||
} | ||
|
||
class Biz extends RapidLoggerSupport { | ||
def doStuff(): Task[String] = for { | ||
_ <- info("3") | ||
} yield { | ||
"done" | ||
} | ||
} | ||
} |