mvv / zilog Edit

Logging library for ZIO

Version Matrix

Zilog

Release Version Snapshot Version Build Status

Structured logging library for ZIO

Using Zilog in your project

Add Zilog to your dependencies

libraryDependencies += "com.github.mvv.zilog" %% "zilog" % "0.1-M14"

If you plan to use custom compound structured arguments (like in the example below), you might want to also add sredded-generic dependency for the deriveStructured macro:

libraryDependencies += "com.github.mvv.sredded" %% "sredded-generic" % "0.1-M2" % Provided

Running the following example program

import com.github.mvv.sredded.StructuredMapping
import com.github.mvv.sredded.generic.deriveStructured
import com.github.mvv.zilog._
import zio.{App, ZEnv, ZIO}

final case class Request(src: String, method: String, path: String)
object Request {
  implicit val structured: StructuredMapping[Request] = deriveStructured
}

object RequestKey extends Logging.Key[Request]("request")
object CorrelationIdKey extends Logging.Key[String]("correlationId")
object CustomerIdKey extends Logging.Key[Long]("customerId")

object LoggingApp extends App {
  implicit val logger: Logger = Logger[LoggingApp.type]
  override def run(args: List[String]): ZIO[ZEnv, Nothing, Int] =
    {
      log.withLogArgs(RequestKey(Request("src", "GET", "/foo")), CorrelationIdKey("someId")) {
        log.info("Logic go brrrrr", CustomerIdKey(123))
      }
    } .provideCustomLayer(Logging.consoleJson()).as(0)
}

should produce something like (as a single line)

{
  "timestamp": "2020-05-01T00:00:00.000Z",
  "fiberId": "#0",
  "logger": "LoggingApp$",
  "level": "INFO",
  "message": "Logic go brrrrr",
  "args": {
    "request": {
      "src": "src",
      "method": "GET",
      "path": "/foo"
    },
    "correlationId": "someId",
    "customerId": 123
  },
  "stackTrace": null,
  "sourceFile": "LoggingApp.scala",
  "sourceClass": "LoggingApp",
  "sourceMethod": "run",
  "sourceLine": 20
}

Submodules

  • zilog-sager allows you to access Logging instances in Sager environments
  • zilog-over-slf4j provides a Logging service that uses SLF4J as a backend