-
Notifications
You must be signed in to change notification settings - Fork 7
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
Showing
10 changed files
with
134 additions
and
106 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,4 @@ | |
metals.sbt | ||
target/ | ||
ast.* | ||
sbt-launch.jar |
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
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
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
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
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
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
61 changes: 37 additions & 24 deletions
61
ducktapeNext/src/main/scala/io/github/arainko/ducktape/internal/Logger.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 |
---|---|---|
@@ -1,67 +1,80 @@ | ||
package io.github.arainko.ducktape.internal | ||
|
||
import io.github.arainko.ducktape.Transformer | ||
import io.github.arainko.ducktape.internal.{ Debug, Metainformation } | ||
|
||
import scala.compiletime.* | ||
import scala.quoted.* | ||
import io.github.arainko.ducktape.Transformer | ||
import io.github.arainko.tooling.FullName | ||
import scala.Ordering.Implicits.* | ||
|
||
private[ducktape] object Logger { | ||
|
||
transparent inline given Level = Level.Info | ||
given Output = Output.StdOut | ||
// Logger Config | ||
private transparent inline def level = Level.Off | ||
private val output = Output.StdOut | ||
private def filter(msg: String, meta: Metainformation) = true | ||
|
||
enum Level { | ||
case Debug, Info, Off | ||
case Off, Debug, Info | ||
} | ||
|
||
object Level { | ||
given Ordering[Level] = Ordering.by(_.ordinal) | ||
} | ||
|
||
enum Output { | ||
case StdOut, Report | ||
|
||
final def print(msg: String)(using Quotes) = | ||
final def print(msg: String, level: Level, meta: Metainformation)(using Quotes) = { | ||
def colored(color: String & Singleton)(msg: String) = s"$color$msg${Console.RESET}" | ||
def blue(msg: String) = colored(Console.BLUE)(msg) | ||
def green(msg: String) = colored(Console.GREEN)(msg) | ||
val formatted = s"${green(s"[${level.toString().toUpperCase()}]")} $msg ${blue(s"[$meta]")}" | ||
this match { | ||
case StdOut => println(msg) | ||
case Report => quotes.reflect.report.info(msg) | ||
case StdOut => if (filter(msg, meta)) println(formatted) | ||
case Report => if (filter(msg, meta)) quotes.reflect.report.info(formatted) | ||
} | ||
} | ||
} | ||
|
||
private val infoTag = s"${Console.GREEN}[INFO]${Console.RESET}" | ||
private val debugTag = s"${Console.GREEN}[DEBUG]${Console.RESET}" | ||
private def blue(msg: String) = s"${Console.BLUE}$msg${Console.RESET}" | ||
|
||
inline def loggedInfo[A](using Level, Output, FullName, Debug[A], Quotes)( | ||
inline def loggedInfo[A](using Metainformation, Quotes)( | ||
inline msg: String | ||
)(value: A) = { | ||
)(value: A)(using Debug[A]) = { | ||
info(msg, value) | ||
value | ||
} | ||
|
||
inline def info(inline msg: String)(using level: Level, output: Output, name: FullName, quotes: Quotes): Unit = | ||
inline def info(inline msg: String)(using name: Metainformation, quotes: Quotes): Unit = | ||
inline level match { | ||
case Level.Debug => () | ||
case Level.Info => output.print(s"$infoTag $msg ${blue(s"[$name]")}") | ||
case Level.Debug => if (level <= Level.Info) output.print(msg, Level.Info, name) | ||
case Level.Info => if (level <= Level.Info) output.print(msg, Level.Info, name) | ||
case Level.Off => () | ||
} | ||
|
||
inline def info[A]( | ||
inline msg: String, | ||
value: A | ||
)(using Level, Output, FullName, Debug[A], Quotes): Unit = | ||
)(using Metainformation, Debug[A], Quotes): Unit = | ||
info(s"$msg: ${Debug.show(value)}") | ||
|
||
inline def loggedDebug[A](using Level, Output, FullName, Debug[A], Quotes)( | ||
inline def loggedDebug[A](using Level, Output, Metainformation, Quotes)( | ||
inline msg: String | ||
)(value: A) = { | ||
)(value: A)(using Debug[A]) = { | ||
debug(msg, value) | ||
value | ||
} | ||
|
||
inline def debug(inline msg: String)(using level: Level, output: Output, name: FullName, quotes: Quotes): Unit = | ||
inline def debug(inline msg: String)(using name: Metainformation, quotes: Quotes): Unit = | ||
inline level match { | ||
case Level.Debug => output.print(s"$debugTag $msg ${blue(s"[$name]")}") | ||
case Level.Info => output.print(s"$infoTag $msg ${blue(s"[$name]")}") | ||
case Level.Debug => if (level <= Level.Debug) output.print(msg, Level.Debug, name) | ||
case Level.Info => if (level <= Level.Debug) output.print(msg, Level.Debug, name) | ||
case Level.Off => () | ||
} | ||
|
||
inline def debug[A](inline msg: String, value: A)(using level: Level, name: FullName, _debug: Debug[A], quotes: Quotes): Unit = | ||
inline def debug[A](inline msg: String, value: A)(using | ||
name: Metainformation, | ||
_debug: Debug[A], | ||
quotes: Quotes | ||
): Unit = | ||
debug(s"$msg: ${Debug.show(value)}") | ||
} |
Oops, something went wrong.