Skip to content

Commit

Permalink
module version change
Browse files Browse the repository at this point in the history
  • Loading branch information
adykaaa committed Jan 20, 2023
1 parent 175e6c3 commit 371f8f7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 77 deletions.
63 changes: 1 addition & 62 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,65 +3,4 @@ httplog

Small but powerful structured logging package for HTTP request logging in Go.

## Example

(see [_example/](./_example/main.go))

```go
package main

import (
"net/http"
"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
"github.com/go-chi/httplog"
)

func main() {
// Logger
logger := httplog.NewLogger("httplog-example", httplog.Options{
JSON: true,
})

// Service
r := chi.NewRouter()
r.Use(httplog.RequestLogger(logger))
r.Use(middleware.Heartbeat("/ping"))

r.Get("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("hello world"))
})

r.Get("/panic", func(w http.ResponseWriter, r *http.Request) {
panic("oh no")
})

r.Get("/info", func(w http.ResponseWriter, r *http.Request) {
oplog := httplog.LogEntry(r.Context())
w.Header().Add("Content-Type", "text/plain")
oplog.Info().Msg("info here")
w.Write([]byte("info here"))
})

r.Get("/warn", func(w http.ResponseWriter, r *http.Request) {
oplog := httplog.LogEntry(r.Context())
oplog.Warn().Msg("warn here")
w.WriteHeader(400)
w.Write([]byte("warn here"))
})

r.Get("/err", func(w http.ResponseWriter, r *http.Request) {
oplog := httplog.LogEntry(r.Context())
oplog.Error().Msg("err here")
w.WriteHeader(500)
w.Write([]byte("err here"))
})

http.ListenAndServe(":5555", r)
}

```

## License

MIT
I modified it so that it takes the logger as a pointer and won't have to create any copies of it, since this library already uses Zerolog (but it expects you to create a new global logger)
4 changes: 2 additions & 2 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
var DefaultOptions = Options{
LogLevel: "info",
LevelFieldName: "level",
JSON: false,
Concise: false,
JSON: true,
Concise: true,
Tags: nil,
SkipHeaders: nil,
TimeFieldFormat: time.RFC3339Nano,
Expand Down
10 changes: 6 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
module github.com/go-chi/httplog
module github.com/adykaaa/httplog/v1

go 1.14

require (
github.com/go-chi/chi/v5 v5.0.7
github.com/rs/zerolog v1.27.0
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
github.com/go-chi/chi/v5 v5.0.8
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/rs/zerolog v1.28.0
golang.org/x/sys v0.4.0 // indirect
)
22 changes: 13 additions & 9 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
github.com/coreos/go-systemd/v22 v22.3.3-0.20220203105225-a9a7ef127534/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/go-chi/chi/v5 v5.0.7 h1:rDTPXLDHGATaeHvVlLcR4Qe0zftYethFucbjVQ1PxU8=
github.com/go-chi/chi/v5 v5.0.7/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
github.com/go-chi/chi/v5 v5.0.8 h1:lD+NLqFcAi1ovnVZpsnObHGW4xb4J8lNmoYVfECH1Y0=
github.com/go-chi/chi/v5 v5.0.8/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40=
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng=
github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/rs/xid v1.3.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/rs/zerolog v1.27.0 h1:1T7qCieN22GVc8S4Q2yuexzBb1EqjbgjSH9RohbMjKs=
github.com/rs/zerolog v1.27.0/go.mod h1:7frBqO0oezxmnO7GF86FY++uy8I0Tk/If5ni1G9Qc0U=
github.com/rs/xid v1.4.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/rs/zerolog v1.28.0 h1:MirSo27VyNi7RJYP3078AA1+Cyzd2GB66qy3aUHvsWY=
github.com/rs/zerolog v1.28.0/go.mod h1:NILgTygv/Uej1ra5XxGf82ZFSLk58MFGAUS2o6usyD0=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18=
golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=

0 comments on commit 371f8f7

Please sign in to comment.