From 5e8da72d560211d2ae2a3e4e881042ce3deb9ef3 Mon Sep 17 00:00:00 2001 From: Christopher Davenport Date: Wed, 19 Jul 2023 15:00:46 -0700 Subject: [PATCH] Update README to simplify getting started --- README.md | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 76dd1a4..c397891 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,8 @@ # http4s-log4cats-contextlog - Logging Middlewares for Http4s [![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.chrisdavenport/http4s-log4cats-contextlog_2.13/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.chrisdavenport/http4s-log4cats-contextlog_2.13) ![Code of Conduct](https://img.shields.io/badge/Code%20of%20Conduct-Scala-blue.svg) +## Intention of Upstreaming + +The goal of this library is to solidify the interface and contribute it to http4s. Any contributions should be made with an understanding that this code will eventually be PR'd to http4s, and altered there in accordance with the http4s license. ## Quick Start @@ -12,7 +15,33 @@ libraryDependencies ++= Seq( ) ``` +So lets drop this into your application. -## Intention of Upstreaming +```scala +import org.http4s.{HttpApp, HttpRoutes} +import org.http4s.client.Client +import org.typelevel.log4cats.StructuredLogger -The goal of this library is to solidify the interface and contribute it to http4s. Any contributions should be made with an understanding that this code will eventually be PR'd to http4s, and altered there in accordance with the http4s license. +val yourHttpApp: HttpApp[F] = ??? +val yourHttpRoutes: HttpRoutes[F] = ??? +val yourClient: Client[F] = ??? +val yourLoger: StructuredLogger[F] = ??? + +import io.chrisdavenport.http4s.log4cats.contextlog.{ + ClientMiddleware, + ServerMiddleware +} + +// This client will automatically log for you +val loggedClient: Client[F] = ClientMiddleware.fromLogger(yourLogger) + .client(client) + +val loggedApp = ServerMiddleware.fromLogger(yourLogger) + .httpApp(yourHttpApp) + +// Does not know status or body for unmatched requests +val loggedRoutes = ServerMiddleware.fromLogger(yourLogger) + .httpRoutes(yourHttpRoutes) +``` + +The defaults will log normal interactions as `Debug`, 4xx excluding 404 as `Warn`, and 5xx as `Error`. \ No newline at end of file