Code Monkey home page Code Monkey logo

zilog's Introduction

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

zilog's People

Contributors

mvv avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.