Skip to content

Commit

Permalink
feat: logging
Browse files Browse the repository at this point in the history
  • Loading branch information
betarixm committed Nov 27, 2023
1 parent a5e8bda commit b510ef4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
5 changes: 4 additions & 1 deletion core/src/main/scala/Block.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,15 @@ object Block extends Logging {

}

class Block(val records: LazyList[Record]) extends AnyVal {
class Block(val records: LazyList[Record]) extends Logging {
def toChars: LazyList[Char] = records.flatMap(_.toChars)

def writeTo(path: Path): File = {
logger.info(s"[Block] Writing block to $path")
val file = File(path)
logger.info(s"[Block] Writing block to ${file.jfile.getAbsolutePath}")
val writer = new BufferedOutputStream(new FileOutputStream(file.jfile))
logger.info(s"[Block] Writer created for ${file.jfile.getAbsolutePath}")

try {
toChars.foreach(writer.write(_))
Expand Down
22 changes: 15 additions & 7 deletions rpc/src/main/scala/ExchangeService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,27 @@ class ExchangeService(
val promise = Promise[SaveReply]

Future {
logger.info(s"[ExchangeServer] Save ($request)")

val block: Block = request.block
try {
logger.info(s"[ExchangeServer] Save ($request)")

val path = outputDirectory / UUID.randomUUID().toString
val block: Block = request.block

logger.info(s"[ExchangeServer] Writing block to $path")
val path = outputDirectory / UUID.randomUUID().toString

block.writeTo(path)
logger.info(s"[ExchangeServer] Writing block to $path")

logger.info(s"[ExchangeServer] Block written to $path")
block.writeTo(path)

promise.success(new SaveReply())
logger.info(s"[ExchangeServer] Block written to $path")

promise.success(new SaveReply())
} catch {
case e: Exception => {
logger.error(s"[ExchangeServer] Error: ${e.getMessage}")
promise.failure(e)
}
}
}(executionContext)

promise.future
Expand Down

0 comments on commit b510ef4

Please sign in to comment.