Skip to content

Commit

Permalink
Merge pull request #14 from davenverse/addReadmeDocs
Browse files Browse the repository at this point in the history
Update README to simplify getting started
  • Loading branch information
ChristopherDavenport committed Jul 20, 2023
2 parents 9af3250 + 5e8da72 commit 8870026
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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`.

0 comments on commit 8870026

Please sign in to comment.