Skip to content

Commit

Permalink
Add logging of main actor messages (#110)
Browse files Browse the repository at this point in the history
* Change Linearized code subfolder

* Add logging of SudokuSolver and SudokuProgressTracker messages

* Bump sbt from 1.8.3 to 1.9.3

* Change name of log file to sudoku.log
  • Loading branch information
eloots authored Aug 4, 2023
1 parent cf2e510 commit bee7632
Show file tree
Hide file tree
Showing 99 changed files with 1,087 additions and 590 deletions.
3 changes: 3 additions & 0 deletions course-management.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ cmt {
# Folder in studentified repo holding the current exercise code
studentified-repo-active-exercise-folder = .

# Folder in linearized repo holding the current exercise code
linearized-repo-active-exercise-folder = code

# List of folders containing test code
test-code-folders = [
"src/test"
Expand Down
5 changes: 1 addition & 4 deletions exercises/exercise_000_sudoku_solver_initial_state/build.sbt
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@

Global / onChangedBuildSource := ReloadOnSourceChanges


lazy val `moving-from-scala-2-to-scala-3` =
(project in file(".")).settings(
scalaVersion := "2.13.10",
Compile / scalacOptions ++= CompileOptions.compileOptions,
libraryDependencies ++= Dependencies.dependencies,
testFrameworks += new TestFramework("munit.Framework"),
)
testFrameworks += new TestFramework("munit.Framework"))

sbt.addCommandAlias("runSolver", "runMain org.lunatechlabs.dotty.SudokuSolverMain")
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,31 @@ object CompileOptions {
lazy val rewriteNoIndent = Seq("-rewrite", "-noindent")
lazy val rewriteOldSyntax = Seq("-rewrite", "-old-syntax")

lazy val compileOptions = Seq(
"-unchecked",
"-deprecation",
"-encoding", "UTF-8",
)
lazy val compileOptions = Seq("-unchecked", "-deprecation", "-encoding", "UTF-8")
}

object Versions {
lazy val akkaVer = "2.6.20"
lazy val logbackVer = "1.2.3"
lazy val mUnitVer = "0.7.26"
lazy val akkaVer = "2.6.20"
lazy val logbackVer = "1.2.3"
lazy val mUnitVer = "0.7.26"
}

object Dependencies {

private lazy val akkaDeps = Seq(
"com.typesafe.akka" %% "akka-actor-typed",
"com.typesafe.akka" %% "akka-slf4j",
"com.typesafe.akka" %% "akka-stream",
).map (_ % Versions.akkaVer)
"com.typesafe.akka" %% "akka-actor-typed",
"com.typesafe.akka" %% "akka-slf4j",
"com.typesafe.akka" %% "akka-stream").map(_ % Versions.akkaVer)

private lazy val akkaTestkitDeps = Seq(
"com.typesafe.akka" %% "akka-actor-testkit-typed" % Versions.akkaVer % Test
)
private lazy val akkaTestkitDeps = Seq("com.typesafe.akka" %% "akka-actor-testkit-typed" % Versions.akkaVer % Test)

private lazy val logbackDeps = Seq (
"ch.qos.logback" % "logback-classic",
).map (_ % Versions.logbackVer)
private lazy val logbackDeps = Seq("ch.qos.logback" % "logback-classic").map(_ % Versions.logbackVer)

private lazy val munitDeps = Seq(
"org.scalameta" %% "munit" % Versions.mUnitVer % Test
)
private lazy val munitDeps = Seq("org.scalameta" %% "munit" % Versions.mUnitVer % Test)

lazy val dependencies: Seq[ModuleID] =
logbackDeps ++
munitDeps ++
akkaDeps ++
akkaTestkitDeps
munitDeps ++
akkaDeps ++
akkaTestkitDeps
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.8.3
sbt.version=1.9.3
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
akka {
loggers = ["akka.event.slf4j.Slf4jLogger"]
loglevel = "INFO"
logging-filter = "akka.event.slf4j.Slf4jLoggingFilter"

log-dead-letters = on
logger-startup-timeout = 30s

Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>

<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>info</level>
<level>INFO</level>
</filter>
<encoder>
<pattern>%date{HH:mm:ss} %-5level [%X{akkaSource}] - %msg%n</pattern>
<pattern>[%date{ISO8601}] [%level] [%logger] [%marker] [%thread] - %msg %n</pattern>
</encoder>
</appender>

<logger name="org.lunatechlabs.dotty" level="info" additivity="false">
<appender-ref ref="console"/>
</logger>

<logger name="akka.actor.RepointableActorRef" level="info" additivity="false">
<appender-ref ref="console"/>
</logger>
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>target/sudoku.log</file>
<encoder>
<pattern>[%date{ISO8601}] [%level] [%logger] [%marker] [%thread] - %msg %n</pattern>
</encoder>
</appender>

<root level="info">
<appender-ref ref="console"/>
<root level="INFO">
<appender-ref ref="STDOUT"/>
<appender-ref ref="FILE"/>
</root>

</configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ class SudokuProgressTracker private (
def trackProgress(updatesInFlight: Int): Behavior[Command] =
Behaviors.receiveMessage {
case NewUpdatesInFlight(updateCount) if updatesInFlight - 1 == 0 =>
context.log.debug("NewUpdatesInFlight({}) - UpdatesInFlight={}", updateCount, updatesInFlight + updateCount)
rowDetailProcessors.foreach { case (_, processor) =>
processor ! SudokuDetailProcessor.GetSudokuDetailState(context.self)
}
collectEndState()
case NewUpdatesInFlight(updateCount) =>
context.log.debug("NewUpdatesInFlight({}) - UpdatesInFlight={}", updateCount, updatesInFlight + updateCount)
trackProgress(updatesInFlight + updateCount)
case msg: SudokuDetailState =>
context.log.error("Received unexpected message in state 'trackProgress': {}", msg)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class SudokuSolver private (context: ActorContext[SudokuSolver.Command], buffer:
rowUpdates.foreach { case SudokuDetailProcessor.RowUpdate(row, cellUpdates) =>
rowDetailProcessors(row) ! SudokuDetailProcessor.Update(cellUpdates, detailProcessorResponseMapper)
}
context.log.debug("InitialRowUpdates: {}", rowUpdates)
progressTracker ! SudokuProgressTracker.NewUpdatesInFlight(rowUpdates.size)
processRequest(Some(sender), System.currentTimeMillis())
case unexpectedMsg =>
Expand All @@ -88,52 +89,95 @@ class SudokuSolver private (context: ActorContext[SudokuSolver.Command], buffer:
response match {
case SudokuDetailProcessor.RowUpdate(rowNr, updates) =>
updates.foreach { case (rowCellNr, newCellContent) =>
context.log.debug("Incoming update for Row({},{})={} ", rowNr, rowCellNr, newCellContent)
val (columnNr, columnCellNr) = rowToColumnCoordinates(rowNr, rowCellNr)
val columnUpdate = Vector(columnCellNr -> newCellContent)
context.log.debug(
"Outgoing update from RowProcessor({}) for Column({}, {})={} ",
rowNr,
columnNr,
columnCellNr,
columnUpdate)
columnDetailProcessors(columnNr) ! SudokuDetailProcessor.Update(
columnUpdate,
detailProcessorResponseMapper)

val (blockNr, blockCellNr) = rowToBlockCoordinates(rowNr, rowCellNr)
val blockUpdate = Vector(blockCellNr -> newCellContent)
context.log.debug(
"Outgoing update from RowProcessor({}) for Block({}, {})={} ",
rowNr,
blockNr,
blockCellNr,
blockUpdate)
blockDetailProcessors(blockNr) ! SudokuDetailProcessor.Update(blockUpdate, detailProcessorResponseMapper)
}
progressTracker ! SudokuProgressTracker.NewUpdatesInFlight(2 * updates.size - 1)
Behaviors.same
case SudokuDetailProcessor.ColumnUpdate(columnNr, updates) =>
updates.foreach { case (colCellNr, newCellContent) =>
context.log.debug("Incoming update for Column({},{})={} ", columnNr, colCellNr, newCellContent)
val (rowNr, rowCellNr) = columnToRowCoordinates(columnNr, colCellNr)
val rowUpdate = Vector(rowCellNr -> newCellContent)
context.log.debug(
"Outgoing update from ColumnProcessor({}) for Row({}, {})={} ",
columnNr,
rowNr,
rowCellNr,
rowUpdate)
rowDetailProcessors(rowNr) ! SudokuDetailProcessor.Update(rowUpdate, detailProcessorResponseMapper)

val (blockNr, blockCellNr) = columnToBlockCoordinates(columnNr, colCellNr)
val blockUpdate = Vector(blockCellNr -> newCellContent)
context.log.debug(
"Outgoing update from ColumnProcessor({}) for Block({}, {})={} ",
columnNr,
blockNr,
blockCellNr,
blockUpdate)
blockDetailProcessors(blockNr) ! SudokuDetailProcessor.Update(blockUpdate, detailProcessorResponseMapper)
}
progressTracker ! SudokuProgressTracker.NewUpdatesInFlight(2 * updates.size - 1)
Behaviors.same
case SudokuDetailProcessor.BlockUpdate(blockNr, updates) =>
updates.foreach { case (blockCellNr, newCellContent) =>
context.log.debug("Incoming update for Block({},{})={} ", blockNr, blockCellNr, newCellContent)
val (rowNr, rowCellNr) = blockToRowCoordinates(blockNr, blockCellNr)
val rowUpdate = Vector(rowCellNr -> newCellContent)
context.log.debug(
"Outgoing update from BlockProcessor({}) for Row({}, {})={} ",
blockNr,
rowNr,
rowCellNr,
rowUpdate)

rowDetailProcessors(rowNr) ! SudokuDetailProcessor.Update(rowUpdate, detailProcessorResponseMapper)

val (columnNr, columnCellNr) = blockToColumnCoordinates(blockNr, blockCellNr)
val columnUpdate = Vector(columnCellNr -> newCellContent)
context.log.debug(
"Outgoing update from BlockProcessor({}) for Column({}, {})={} ",
blockNr,
columnNr,
columnCellNr,
columnUpdate)

columnDetailProcessors(columnNr) ! SudokuDetailProcessor.Update(
columnUpdate,
detailProcessorResponseMapper)
}
progressTracker ! SudokuProgressTracker.NewUpdatesInFlight(2 * updates.size - 1)
Behaviors.same
case unchanged @ SudokuDetailProcessor.SudokuDetailUnchanged =>
context.log.debug("SudokuDetailUnchanged")
progressTracker ! SudokuProgressTracker.NewUpdatesInFlight(-1)
Behaviors.same
}
case SudokuProgressTrackerResponseWrapped(result) =>
result match {
case SudokuProgressTracker.Result(sudoku) =>
context.log.info(s"Sudoku processing time: ${System.currentTimeMillis() - startTime} milliseconds")
context.log.debug("Result: {}", sudoku)
requestor.get ! SudokuSolution(sudoku)
resetAllDetailProcessors()
buffer.unstashAll(idle())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
Global / onChangedBuildSource := ReloadOnSourceChanges


lazy val `moving-from-scala-2-to-scala-3` =
(project in file(".")).settings(
scalaVersion := "3.3.0",
Compile / scalacOptions ++= CompileOptions.compileOptions,
libraryDependencies ++= Dependencies.dependencies,
testFrameworks += new TestFramework("munit.Framework"),
)
testFrameworks += new TestFramework("munit.Framework"))

sbt.addCommandAlias("runSolver", "runMain org.lunatechlabs.dotty.SudokuSolverMain")
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,31 @@ object CompileOptions {
lazy val rewriteNoIndent = Seq("-rewrite", "-noindent")
lazy val rewriteOldSyntax = Seq("-rewrite", "-old-syntax")

lazy val compileOptions = Seq(
"-unchecked",
"-deprecation",
"-encoding", "UTF-8",
"-source:future-migration",
)
lazy val compileOptions = Seq("-unchecked", "-deprecation", "-encoding", "UTF-8", "-source:future-migration")
}

object Versions {
lazy val akkaVer = "2.6.20"
lazy val logbackVer = "1.2.3"
lazy val mUnitVer = "0.7.26"
lazy val akkaVer = "2.6.20"
lazy val logbackVer = "1.2.3"
lazy val mUnitVer = "0.7.26"
}

object Dependencies {

private lazy val akkaDeps = Seq(
"com.typesafe.akka" %% "akka-actor-typed",
"com.typesafe.akka" %% "akka-slf4j",
"com.typesafe.akka" %% "akka-stream",
).map (_ % Versions.akkaVer)
"com.typesafe.akka" %% "akka-actor-typed",
"com.typesafe.akka" %% "akka-slf4j",
"com.typesafe.akka" %% "akka-stream").map(_ % Versions.akkaVer)

private lazy val akkaTestkitDeps = Seq(
"com.typesafe.akka" %% "akka-actor-testkit-typed" % Versions.akkaVer % Test
)
private lazy val akkaTestkitDeps = Seq("com.typesafe.akka" %% "akka-actor-testkit-typed" % Versions.akkaVer % Test)

private lazy val logbackDeps = Seq (
"ch.qos.logback" % "logback-classic",
).map (_ % Versions.logbackVer)
private lazy val logbackDeps = Seq("ch.qos.logback" % "logback-classic").map(_ % Versions.logbackVer)

private lazy val munitDeps = Seq(
"org.scalameta" %% "munit" % Versions.mUnitVer % Test
)
private lazy val munitDeps = Seq("org.scalameta" %% "munit" % Versions.mUnitVer % Test)

lazy val dependencies: Seq[ModuleID] =
logbackDeps ++
munitDeps ++
akkaDeps ++
akkaTestkitDeps
munitDeps ++
akkaDeps ++
akkaTestkitDeps
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.8.3
sbt.version=1.9.3
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
akka {
loggers = ["akka.event.slf4j.Slf4jLogger"]
loglevel = "INFO"
logging-filter = "akka.event.slf4j.Slf4jLoggingFilter"

log-dead-letters = on
logger-startup-timeout = 30s

Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>

<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>info</level>
<level>INFO</level>
</filter>
<encoder>
<pattern>%date{HH:mm:ss} %-5level [%X{akkaSource}] - %msg%n</pattern>
<pattern>[%date{ISO8601}] [%level] [%logger] [%marker] [%thread] - %msg %n</pattern>
</encoder>
</appender>

<logger name="org.lunatechlabs.dotty" level="info" additivity="false">
<appender-ref ref="console"/>
</logger>

<logger name="akka.actor.RepointableActorRef" level="info" additivity="false">
<appender-ref ref="console"/>
</logger>
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>target/sudoku.log</file>
<encoder>
<pattern>[%date{ISO8601}] [%level] [%logger] [%marker] [%thread] - %msg %n</pattern>
</encoder>
</appender>

<root level="info">
<appender-ref ref="console"/>
<root level="INFO">
<appender-ref ref="STDOUT"/>
<appender-ref ref="FILE"/>
</root>

</configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ class SudokuProgressTracker private (
def trackProgress(updatesInFlight: Int): Behavior[Command] =
Behaviors.receiveMessage {
case NewUpdatesInFlight(updateCount) if updatesInFlight - 1 == 0 =>
context.log.debug("NewUpdatesInFlight({}) - UpdatesInFlight={}", updateCount, updatesInFlight + updateCount)
rowDetailProcessors.foreach { case (_, processor) =>
processor ! SudokuDetailProcessor.GetSudokuDetailState(context.self)
}
collectEndState()
case NewUpdatesInFlight(updateCount) =>
context.log.debug("NewUpdatesInFlight({}) - UpdatesInFlight={}", updateCount, updatesInFlight + updateCount)
trackProgress(updatesInFlight + updateCount)
case msg: SudokuDetailState =>
context.log.error("Received unexpected message in state 'trackProgress': {}", msg)
Expand Down
Loading

0 comments on commit bee7632

Please sign in to comment.