Skip to content

Commit

Permalink
#1 - Added basic README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
blondacz committed Apr 24, 2023
1 parent 99c1f68 commit d872f02
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 14 deletions.
41 changes: 40 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,40 @@
# log-writter
# log-writer

This scala library supports creating performance logfile that.

## Usage

```kotlin
//gradle
dependencies {
implementation("dev.g4s:log-writer_2.13:0.1.0")
}
```

```scala
//scala
import cats.effect.IO
import cats.effect.unsafe.implicits.global
import fs2._
import fs2.io.file._
import g4s.log.LogLine._
import g4s.log.StringFileWriter.StringFileWriterOps

val files = Files[IO]

val logFile = for {
tmp <- files.createTempFile(Some(buildPath.resolve("build")), "perf", "log", None)
w <- LogReporter(tmp)
_ <- Assertion.AllOK.write(w)
_ <- Run(classOf[MyLog], 123L).write(w)
_ <- ScenarioStart("BasicPerf", 233).write(w)
_ <- ScenarioStart("BasicPerf", 234).write(w)
_ <- Stream.emits(Seq(1,2,3)).through(report(w)).compile.drain
_ <- ScenarioEnd("BasicPerf", 333).write(w)
_ <- ScenarioEnd("BasicPerf", 334).write(w)
_ <- w.close()

} yield ()

logFile.unsafeRunSync()
```
2 changes: 1 addition & 1 deletion lib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
scala
`java-library`
id("com.github.maiflai.scalatest") version "0.32"

`maven-publish`
}

repositories {
Expand Down
24 changes: 12 additions & 12 deletions lib/src/test/scala/g4s/log/LogReporterTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ class LogReporterTest extends AnyFreeSpec with Matchers {
val expectedFileContents: String =
s"""ASSERTION AAECAAIFAAAAAAAAAFlA
|RUN g4s.log.MyLog mylog 123\t \t3.9.3
|USER BasicSimulation2 START 233
|USER BasicSimulation2 START 234
|USER BasicPerf2 START 233
|USER BasicPerf2 START 234
|REQUEST request_1 111 112 OK\t\u0020
|REQUEST request_1 211 212 OK\t\u0020
|REQUEST request_1 311 312 OK\t\u0020
|USER BasicSimulation2 END 333
|USER BasicSimulation2 END 334
|USER BasicPerf2 END 333
|USER BasicPerf2 END 334
|""".stripMargin


Expand All @@ -37,13 +37,13 @@ class LogReporterTest extends AnyFreeSpec with Matchers {
w <- LogReporter(tmp)
_ <- w.write(Assertion.AllOK)
_ <- w.write(Run(classOf[MyLog], 123L))
_ <- w.write(ScenarioStart("BasicSimulation2", 233))
_ <- w.write(ScenarioStart("BasicSimulation2", 234))
_ <- w.write(ScenarioStart("BasicPerf2", 233))
_ <- w.write(ScenarioStart("BasicPerf2", 234))
_ <- w.write(Response.ok("request_1", 111, 112))
_ <- w.write(Response.ok("request_1", 211, 212))
_ <- w.write(Response.ok("request_1", 311, 312))
_ <- w.write(ScenarioEnd("BasicSimulation2", 333))
_ <- w.write(ScenarioEnd("BasicSimulation2", 334))
_ <- w.write(ScenarioEnd("BasicPerf2", 333))
_ <- w.write(ScenarioEnd("BasicPerf2", 334))
_ <- w.close()
perflog <- files.readUtf8(tmp).compile.string
} yield perflog
Expand All @@ -65,11 +65,11 @@ class LogReporterTest extends AnyFreeSpec with Matchers {
w <- LogReporter(tmp)
_ <- Assertion.AllOK.write(w)
_ <- Run(classOf[MyLog], 123L).write(w)
_ <- ScenarioStart("BasicSimulation2", 233).write(w)
_ <- ScenarioStart("BasicSimulation2", 234).write(w)
_ <- ScenarioStart("BasicPerf2", 233).write(w)
_ <- ScenarioStart("BasicPerf2", 234).write(w)
_ <- Stream.emits(Seq(1,2,3)).through(report(w)).compile.drain
_ <- ScenarioEnd("BasicSimulation2", 333).write(w)
_ <- ScenarioEnd("BasicSimulation2", 334).write(w)
_ <- ScenarioEnd("BasicPerf2", 333).write(w)
_ <- ScenarioEnd("BasicPerf2", 334).write(w)
_ <- w.close()
perflog <- files.readUtf8(tmp).compile.string
} yield perflog
Expand Down

0 comments on commit d872f02

Please sign in to comment.