Skip to content

Commit 5ba8bce

Browse files
authored
Update readme with latest change
1 parent 3883861 commit 5ba8bce

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

README.md

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,36 @@
1-
[![go.dev Reference](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go&logoColor=white&style=flat)](https://pkg.go.dev/github.com/aaronvb/logrequest) [![CircleCI](https://img.shields.io/circleci/build/github/aaronvb/logrequest)](https://circleci.com/gh/aaronvb/logrequest)
1+
# logrequest
2+
[![go.dev Reference](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go&logoColor=white&style=flat)](https://pkg.go.dev/github.com/aaronvb/logrequest) [![Workflow](https://img.shields.io/github/workflow/status/aaronvb/logrequest/Go?label=build%2Ftests&style=flat)](https://github.com/aaronvb/logrequest/actions/workflows/go.yml)
23

3-
# aaronvb/logrequest
4-
Package `aaronvb/logrequest` is a Go middleware log output inspired by the Ruby on Rails log output for requests. Example output:
4+
This is a Go middleware log output inspired by the Ruby on Rails log output for requests. Example output:
55

66
```sh
77
Started GET "/" 127.0.0.1:12345 HTTP/1.1
88
Completed 200 in 3.7455ms
99
```
1010

11-
The output can directly sent to `log.Logger` or to a map[string]string with the key `started` and `completed`.
12-
1311
## Install
1412
```sh
1513
go get -u github.com/aaronvb/logrequest
1614
```
1715

16+
## Using logrequest
17+
The three ways you can have logrequest return request data:
18+
19+
- Directly sent to `log.Logger` using the `ToLogger(logger *log.Logger)` method.
20+
- Return a `map[string]string` with the key `started` and `completed` using the `ToString()` method.
21+
- Return a `RequestFields` struct that contains the fields in the request. (See below)
22+
```go
23+
type RequestFields struct {
24+
Method string
25+
Url string
26+
RemoteAddress string
27+
Protocol string
28+
Time time.Time
29+
Duration time.Duration
30+
StatusCode int
31+
}
32+
```
33+
1834
## Options
1935
There are two optional options you can pass to the `LogRequest` struct:
2036

0 commit comments

Comments
 (0)