treelog


License

License

GroupId

GroupId

com.casualmiracles
ArtifactId

ArtifactId

treelog_2.12
Last Version

Last Version

1.4.10
Release Date

Release Date

Type

Type

jar
Description

Description

treelog
treelog
Project URL

Project URL

https://github.com/lancewalton/treelog
Project Organization

Project Organization

com.casualmiracles
Source Code Management

Source Code Management

https://github.com/lancewalton/treelog

Download treelog_2.12

How to add to project

<!-- https://jarcasting.com/artifacts/com.casualmiracles/treelog_2.12/ -->
<dependency>
    <groupId>com.casualmiracles</groupId>
    <artifactId>treelog_2.12</artifactId>
    <version>1.4.10</version>
</dependency>
// https://jarcasting.com/artifacts/com.casualmiracles/treelog_2.12/
implementation 'com.casualmiracles:treelog_2.12:1.4.10'
// https://jarcasting.com/artifacts/com.casualmiracles/treelog_2.12/
implementation ("com.casualmiracles:treelog_2.12:1.4.10")
'com.casualmiracles:treelog_2.12:jar:1.4.10'
<dependency org="com.casualmiracles" name="treelog_2.12" rev="1.4.10">
  <artifact name="treelog_2.12" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.casualmiracles', module='treelog_2.12', version='1.4.10')
)
libraryDependencies += "com.casualmiracles" % "treelog_2.12" % "1.4.10"
[com.casualmiracles/treelog_2.12 "1.4.10"]

Dependencies

compile (2)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.12.8
org.scalaz : scalaz-core_2.12 jar 7.3.0-M18

test (5)

Group / Artifact Type Version
org.scalaz : scalaz-scalacheck-binding_2.12 jar 7.3.0-M18
org.scalaz : scalaz-effect_2.12 jar 7.3.0-M18
org.scalatest : scalatest_2.12 jar 3.0.6
io.argonaut : argonaut_2.12 jar 6.2.2
io.argonaut : argonaut-scalaz_2.12 jar 6.2.2

Project Modules

There are no modules declared in this project.

treelog

Gitter

Build Status

It is often necessary to understand exactly what happened in a computation: what went right, what went wrong, what was done with what, why it was done, and how a result was derived.

Such complex computations are trees, and so attempting to describe whats going on in a linear fashion is difficult to follow after the fact. What treelog offers is a means of writing a log together with a computation, with values computed on the way with all information relevant to the computation.

Logtree is a veritable complect of computation and description in perfect harmony.

TreeLog achieves this remarkable feat with a Writer monad writing to a Tree representing the hierarchical log of computation.

Getting TreeLog

For Scala 2.13.x and cats 2.2.0:

libraryDependencies ++= Seq("com.casualmiracles" %% "treelog-cats" % "1.6.0")

For Scala 2.12.x and cats 2.0.0:

libraryDependencies ++= Seq("com.casualmiracles" %% "treelog-cats" % "1.6.0")

For Scala 2.12.x amd 2.11.x and scalaz 7.3.x:

libraryDependencies ++= Seq(
    "com.casualmiracles" %% "treelog" % "1.4.10",
    "org.scalaz" %% "scalaz-core" % "7.3.0-M18")

For Scala 2.12.x and scalaz 7.2.x:

libraryDependencies ++= Seq(
    "com.casualmiracles" %% "treelog-scalaz-72x" % "1.4.3",
    "org.scalaz" %% "scalaz-core" % "7.2.8")

Older Releases

For Scala 2.12.x and cats 1.6.0:

libraryDependencies ++= Seq("com.casualmiracles" %% "treelog-cats" % "1.4.9")

For Scala 2.12.x and scalaz 7.1.x:

libraryDependencies ++= Seq(
    "com.casualmiracles" %% "treelog-scalaz-71x" % "1.4.0",
    "org.scalaz" %% "scalaz-core" % "7.1.11")

For Scala 2.11.x and scalaz 7.2.x:

libraryDependencies ++= Seq(
    "com.casualmiracles" %% "treelog" % "1.3.0",
    "org.scalaz" %% "scalaz-core" % "7.2.0")

For Scala 2.11.x and scalaz 7.1.x:

libraryDependencies ++= Seq(
    "com.casualmiracles" %% "treelog" % "1.2.6",
    "org.scalaz" %% "scalaz-core" % "7.1.7")

For Scala 2.10.x

libraryDependencies ++= Seq(
    "com.casualmiracles" %% "treelog" % "1.2.2",
    "org.scalaz" %% "scalaz-core" % "7.0.6")

Quick Start TL;DR

import treelog.LogTreeSyntaxWithoutAnnotations._
import scalaz._, Scalaz._

// syntax for logging something
val one: DescribedComputation[Int] = 1 ~> "The number one"

// syntax for logging something and include the value in the log
val oneA: DescribedComputation[Int] = 1 ~> (v => s"The value is $v")

// Extract the result ( a scalaz.\/ ) and log (a LogTree which is a type alias for scalaz.Tree[LogTreeLabel[A]])
val v: \/[String, Int] = one.run.value
val logtree: LogTree = one.run.written

// turn the LogTree into a String
val logTreeString = logtree.shows

// In for comprehensions with a top level description
val result: DescribedComputation[Int] = 
 "Adding up" ~< { 
  for {
   foo <- 1 ~> ("foo = " + _)
   bar <- 2 ~> ("bar = " + _)
   foobar <- (foo + bar) ~> ("foobar = " + _)
  } yield foobar 
 }

println(result.run.written.shows)
// prints:
// Adding up
//   foo = 1
//   bar = 2
//   foobar = 3

Now don't be lazy and read the scaladoc.

TreeLog Examples

QuadraticRootsExample.scala and OptionsAndEithersExample.scala in the test package is the simplest way to see how to use TreeLog. FuturesExample.scala demonstrates how you can combine the results of several parallel computations.

The quadratic example does the extremely important job of logging the computation of roots of a quadratic equation. This:

root(Parameters(2, 5, 3)).run.written.shows

results in

   
Extracting root
  Calculating Numerator
    Calculating Determinant
      Calculating b^2
        Got b: 5.0
        Got b^2: 25.0
      Calculating 4ac
        Got a: 2.0
        Got c: 3.0
        Got 4ac: 24.0
      Got b^2 - 4ac: 1.0
    Calculating sqrt(determinant)
      Determinant (1.0) is >= 0
      Got sqrt(determinant): 1.0
    Got b: 5.0
    Got -b: -5.0
    Got -b + sqrt(determinant): -4.0
  Calculating Denominator
    Got a: 2.0
    Got 2a: 4.0
  Got root = numerator / denominator: -1.0

Or, in the case of a failure (when the roots are complex)

root(Parameters(2, 5, 10)).run.written.shows

gives

    
Extracting root: Failed
  Calculating Numerator: Failed
    Calculating Determinant
      Calculating b^2
        Got b: 5.0
        Got b^2: 25.0
      Calculating 4ac
        Got a: 2.0
        Got c: 10.0
        Got 4ac: 80.0
      Got b^2 - 4ac: -55.0
    Calculating sqrt(determinant): Failed
      Determinant (-55.0) is < 0: Failed

Annotations

AnnotationsExample.scala shows how nodes in the log tree can be annotated with important information for your program to use later. This is useful, for example, when you want to audit a process that affects multiple entities, and you want to make sure that the audit trail is associated with each of the modified entities. You can use the annotation facility to carry the key (or something richer) for each modified entity.

Resources

  • Channing's blog at typelevel.
  • @oranda's project to give TreeLog a GUI, the ScalaJS ReactTreeView

Versions

Version
1.4.10
1.4.9
1.4.6
1.4.3
1.4.2
1.4.0