-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from TinkoffCreditSystems/master
upd
- Loading branch information
Showing
21 changed files
with
149 additions
and
45 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package tofu | ||
|
||
import cats.effect.ExitCase | ||
|
||
object GuaranteeSuite { | ||
|
||
def summonInstancesForBracket[F[_]: BracketThrow](): Unit = { | ||
implicitly[Guarantee[F]] | ||
implicitly[Finally[F, TConst[ExitCase[Throwable], *]]] | ||
() | ||
} | ||
|
||
} |
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
2 changes: 1 addition & 1 deletion
2
logging/structured/src/main/scala-2.12/tofu/logging/LogsVOps.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,3 +1,3 @@ | ||
package tofu.logging | ||
|
||
trait LogsVOps[I[_], F[_]] | ||
trait LogsVOps[+I[_], F[_]] |
2 changes: 1 addition & 1 deletion
2
logging/structured/src/main/scala-2.13/tofu/logging/LogsVOps.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
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
43 changes: 43 additions & 0 deletions
43
logging/util/src/main/scala/tofu/logging/atom/AtomLogger.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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package tofu.logging.atom | ||
import java.time.Instant | ||
import java.util.concurrent.TimeUnit | ||
|
||
import cats.effect.Clock | ||
import cats.{Applicative, FlatMap} | ||
import tofu.concurrent.Atom | ||
import tofu.higherKind.Embed | ||
import tofu.logging.{LoggedValue, Logging, Logs} | ||
import tofu.syntax.monadic._ | ||
|
||
import scala.reflect.{ClassTag, classTag} | ||
|
||
final case class LogLine( | ||
loggerName: String, | ||
level: Logging.Level, | ||
message: String, | ||
timestamp: Instant, | ||
values: Vector[LoggedValue], | ||
) | ||
|
||
class AtomLogging[F[_]: FlatMap: Clock](log: Atom[F, Vector[LogLine]], name: String) extends Logging[F] { | ||
override def write(level: Logging.Level, message: String, values: LoggedValue*): F[Unit] = | ||
Clock[F].realTime(TimeUnit.MILLISECONDS).flatMap { time => | ||
log.update( | ||
_ :+ LogLine( | ||
loggerName = name, | ||
level = level, | ||
message = message, | ||
timestamp = Instant.ofEpochMilli(time), | ||
values = values.toVector | ||
) | ||
) | ||
} | ||
|
||
} | ||
|
||
final case class AtomLogs[I[_]: Applicative, F[_]: FlatMap: Clock](flog: F[Atom[F, Vector[LogLine]]]) | ||
extends Logs[I, F] { | ||
def forService[Svc: ClassTag]: I[Logging[F]] = byName(classTag[Svc].runtimeClass.getName) | ||
def byName(name: String): I[Logging[F]] = | ||
Embed.of(flog.map[Logging[F]](new AtomLogging[F](_, name))).pure[I] | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
sbt.version = 1.3.6 | ||
sbt.version = 1.3.7 |
19 changes: 9 additions & 10 deletions
19
...g/src/main/scala/tofu/logging/ZLogs.scala → ...main/scala/tofu/logging/zlogs/ZLogs.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,24 +1,23 @@ | ||
package tofu.logging | ||
package tofu.logging.zlogs | ||
|
||
import org.slf4j.LoggerFactory | ||
import tofu.logging.{Loggable, Logging} | ||
import tofu.logging.Logging.loggerForService | ||
import tofu.logging.impl.{UIOZLogging, URIOZLoggingImpl} | ||
import zio.{UIO, URIO} | ||
|
||
import tofu.logging.zlogs.impl.{UIOZLogging, URIOZLoggingImpl} | ||
import zio.UIO | ||
import scala.reflect.ClassTag | ||
|
||
trait ZLogs[R] extends Logs[UIO, URIO[R, *]] | ||
|
||
object ZLogs { | ||
val uio: Logs[UIO, UIO] = new Logs[UIO, UIO] { | ||
val uio: ZLogs[Any] = new ZLogs[Any] { | ||
def forService[Svc: ClassTag]: UIO[Logging[UIO]] = | ||
UIO.effectTotal(new UIOZLogging(loggerForService[Svc])) | ||
def byName(name: String): UIO[Logging[UIO]] = UIO.effectTotal(new UIOZLogging(LoggerFactory.getLogger(name))) | ||
} | ||
|
||
def withContext[R: Loggable]: Logs[UIO, URIO[R, *]] = new Logs[UIO, URIO[R, *]] { | ||
def forService[Svc: ClassTag]: UIO[Logging[URIO[R, *]]] = | ||
def withContext[R: Loggable]: ZLogs[R] = new ZLogs[R] { | ||
def forService[Svc: ClassTag]: UIO[ZLogging[R]] = | ||
UIO.effectTotal(new URIOZLoggingImpl(loggerForService[Svc])) | ||
override def byName(name: String): UIO[Logging[URIO[R, *]]] = | ||
override def byName(name: String): UIO[ZLogging[R]] = | ||
UIO.effectTotal(new URIOZLoggingImpl[R](LoggerFactory.getLogger(name))) | ||
} | ||
} |
3 changes: 2 additions & 1 deletion
3
...scala/tofu/logging/impl/UIOZLogging.scala → ...tofu/logging/zlogs/impl/UIOZLogging.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
3 changes: 2 additions & 1 deletion
3
.../tofu/logging/impl/URIOZLoggingImpl.scala → ...logging/zlogs/impl/URIOZLoggingImpl.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
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package tofu.logging | ||
|
||
import zio.{UIO, URIO} | ||
|
||
package object zlogs { | ||
type ZLogs[R] = Logs[UIO, URIO[R, *]] | ||
type ZLogging[R] = Logging[URIO[R, *]] | ||
} |