File tree Expand file tree Collapse file tree 1 file changed +21
-5
lines changed Expand file tree Collapse file tree 1 file changed +21
-5
lines changed Original file line number Diff line number Diff line change 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 )
2
3
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:
5
5
6
6
``` sh
7
7
Started GET " /" 127.0.0.1:12345 HTTP/1.1
8
8
Completed 200 in 3.7455ms
9
9
```
10
10
11
- The output can directly sent to ` log.Logger ` or to a map[ string] string with the key ` started ` and ` completed ` .
12
-
13
11
## Install
14
12
``` sh
15
13
go get -u github.com/aaronvb/logrequest
16
14
```
17
15
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
+
18
34
## Options
19
35
There are two optional options you can pass to the ` LogRequest ` struct:
20
36
You can’t perform that action at this time.
0 commit comments