Skip to content

Commit

Permalink
Provide colored output
Browse files Browse the repository at this point in the history
  • Loading branch information
propensive committed Nov 5, 2023
1 parent aed3aa3 commit 9870ea0
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 6 deletions.
7 changes: 6 additions & 1 deletion fury
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,14 @@ project eucalyptus
sources src/syslog
include guillotine/core eucalyptus/core

module ansi
compiler scala
sources src/ansi
include escapade/core eucalyptus/core

module test
compiler scala
sources src/test
include probably/cli eucalyptus/syslog
include probably/cli eucalyptus/syslog eucalyptus/ansi
main eucalyptus.Tests

23 changes: 23 additions & 0 deletions src/ansi/ansi.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package eucalyptus

import escapade.*
import iridescence.*
import anticipation.*
import gossamer.*
import spectacular.*
import hieroglyph.textWidthCalculation.uniform

package logFormats:
given standardColor[TargetType]: LogFormat[TargetType] = entry =>
given displayLevel: Displayable[Level] = level =>
val color = level match
case Level.Fine => colors.LightSeaGreen
case Level.Info => colors.YellowGreen
case Level.Warn => colors.Gold
case Level.Fail => colors.Tomato

e"${Bg(color)}[${colors.Black}($Bold( ${level.show.upper} ))]"

val realm: Output = e"${colors.MediumSeaGreen}(${entry.realm.show.fit(8)})"

e"${colors.SlateGray}(${Log.dateFormat.format(entry.timestamp).nn.tt}) ${entry.level} $realm ${entry.message}\n".render
2 changes: 1 addition & 1 deletion src/core/log.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import scala.language.experimental.captureChecking

object Log:

private val dateFormat = jt.SimpleDateFormat(t"yyyy-MMM-dd HH:mm:ss.SSS".s)
val dateFormat = jt.SimpleDateFormat(t"yyyy-MMM-dd HH:mm:ss.SSS".s)

inline def fine
[ValueType]
Expand Down
4 changes: 2 additions & 2 deletions src/core/logging.scala
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ extends Logger:
funnel.put(entry)

object LogFormat:
given standardAnsi[TargetType]: LogFormat[TargetType] = entry =>
given standard[TargetType]: LogFormat[TargetType] = entry =>
import textWidthCalculation.uniform
val realm: Message = msg"${entry.realm.show.fit(8)}"
msg"${entry.timestamp} ${entry.level} $realm ${entry.message}".text+t"\n"
msg"${Log.dateFormat.format(entry.timestamp).nn.tt} ${entry.level} $realm ${entry.message}".text+t"\n"

trait LogFormat[TargetType]:
def apply(entry: Entry): Text
Expand Down
6 changes: 4 additions & 2 deletions src/test/tests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ import turbulence.*, stdioSources.jvm
object Tests extends Suite(t"Eucalyptus tests"):
def run(): Unit =
import Level.*
given LogFormat[Out.type] = logFormats.standardColor[Out.type]
given LogFormat[Err.type] = logFormats.standardColor[Err.type]
supervise:
given Log = Log:
case Warn() => Err
case Warn() => Out
case Fail() => Out
case _ => Syslog(t"tab")
case _ => Out//Syslog(t"tab")

test(t"Log something"):
given realm: Realm = realm"test"
Expand Down

0 comments on commit 9870ea0

Please sign in to comment.