Skip to content

Commit

Permalink
Merge branch 'feature/refactor-logging-v1' into main-v1
Browse files Browse the repository at this point in the history
  • Loading branch information
VivianAllen committed Jul 30, 2021
2 parents 5632e25 + 363ba6a commit cecbce0
Show file tree
Hide file tree
Showing 17 changed files with 150 additions and 37 deletions.
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,15 @@ test:
go test -v -count=1 -race -cover ./...

.PHONY: test

audit:
go list -json -m all | nancy sleuth --exclude-vulnerability-file ./.nancy-ignore
.PHONY: audit

build:
go build ./...
.PHONY: build

.PHONY: lint
lint:
exit
15 changes: 15 additions & 0 deletions ci/audit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
platform: linux

image_resource:
type: docker-image
source:
repository: onsdigital/dp-concourse-tools-nancy
tag: latest

inputs:
- name: dp-net
path: dp-net

run:
path: dp-net/ci/scripts/audit.sh
16 changes: 16 additions & 0 deletions ci/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---

platform: linux

image_resource:
type: docker-image
source:
repository: golang
tag: latest

inputs:
- name: dp-net
path: dp-net

run:
path: dp-net/ci/scripts/build.sh
15 changes: 15 additions & 0 deletions ci/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---

platform: linux

image_resource:
type: docker-image
source:
repository: golang
tag: 1.16

inputs:
- name: dp-net

run:
path: dp-net/ci/scripts/lint.sh
7 changes: 7 additions & 0 deletions ci/scripts/audit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash -eux

cwd=$(pwd)

pushd $cwd/dp-net
make audit
popd
7 changes: 7 additions & 0 deletions ci/scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash -eux

cwd=$(pwd)

pushd $cwd/dp-net
make build
popd
7 changes: 7 additions & 0 deletions ci/scripts/lint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash -eux

cwd=$(pwd)

pushd $cwd/dp-net
make lint
popd
7 changes: 7 additions & 0 deletions ci/scripts/unit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash -eux

cwd=$(pwd)

pushd $cwd/dp-net
make test
popd
16 changes: 16 additions & 0 deletions ci/unit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---

platform: linux

image_resource:
type: docker-image
source:
repository: golang
tag: latest

inputs:
- name: dp-net
path: dp-net

run:
path: dp-net/ci/scripts/unit.sh
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ module github.com/ONSdigital/dp-net
go 1.13

require (
github.com/ONSdigital/dp-api-clients-go v1.28.0
github.com/ONSdigital/log.go v1.0.1
github.com/ONSdigital/dp-api-clients-go v1.34.3
github.com/ONSdigital/log.go/v2 v2.0.5
github.com/facebookgo/freeport v0.0.0-20150612182905-d4adf43b75b9
github.com/gorilla/mux v1.8.0
github.com/justinas/alice v1.2.0
github.com/pkg/errors v0.9.1
github.com/smartystreets/goconvey v1.6.4
golang.org/x/net v0.0.0-20200822124328-c89045814202
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b
)
33 changes: 22 additions & 11 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
github.com/ONSdigital/dp-api-clients-go v1.28.0 h1:ExIUlHC6uBdBlFwt/gAI0ApSzpyigy0NWJFK3XCwSVc=
github.com/ONSdigital/dp-api-clients-go v1.28.0/go.mod h1:iyJy6uRL4B6OYOJA0XMr5UHt6+Q8XmN9uwmURO+9Oj4=
github.com/ONSdigital/dp-api-clients-go v1.34.3 h1:nS3ZG3Eql9T68Q0IFehpnqkUy2AFoTDktVgaD90Yj+s=
github.com/ONSdigital/dp-api-clients-go v1.34.3/go.mod h1:kX+YKuoLYLfkeLHMvQKRRydZVxO7ZEYyYiwG2xhV51E=
github.com/ONSdigital/dp-healthcheck v1.0.5 h1:DXnohGIqXaLLeYGdaGOhgkZjAbWMNoLAjQ3EgZeMT3M=
github.com/ONSdigital/dp-healthcheck v1.0.5/go.mod h1:2wbVAUHMl9+4tWhUlxYUuA1dnf2+NrwzC+So5f5BMLk=
github.com/ONSdigital/dp-mocking v0.0.0-20190905163309-fee2702ad1b9 h1:+WXVfTDyWXY1DQRDFSmt1b/ORKk5c7jGiPu7NoeaM/0=
Expand All @@ -8,36 +9,40 @@ github.com/ONSdigital/dp-net v1.0.5-0.20200805082802-e518bc287596/go.mod h1:wDVh
github.com/ONSdigital/dp-net v1.0.5-0.20200805145012-9227a11caddb/go.mod h1:MrSZwDUvp8u1VJEqa+36Gwq4E7/DdceW+BDCvGes6Cs=
github.com/ONSdigital/dp-net v1.0.5-0.20200805150805-cac050646ab5/go.mod h1:de3LB9tedE0tObBwa12dUOt5rvTW4qQkF5rXtt4b6CE=
github.com/ONSdigital/dp-net v1.0.7/go.mod h1:1QFzx32FwPKD2lgZI6MtcsUXritsBdJihlzIWDrQ/gc=
github.com/ONSdigital/go-ns v0.0.0-20191104121206-f144c4ec2e58 h1:XHnzoC7TxueLAfkBpblPiwaIxjngGv1VNVZhvE4jY6w=
github.com/ONSdigital/dp-net v1.0.12/go.mod h1:2lvIKOlD4T3BjWQwjHhBUO2UNWDk82u/+mHRn0R3C9A=
github.com/ONSdigital/go-ns v0.0.0-20191104121206-f144c4ec2e58/go.mod h1:iWos35il+NjbvDEqwtB736pyHru0MPFE/LqcwkV1wDc=
github.com/ONSdigital/log.go v1.0.0/go.mod h1:UnGu9Q14gNC+kz0DOkdnLYGoqugCvnokHBRBxFRpVoQ=
github.com/ONSdigital/log.go v1.0.1-0.20200805084515-ee61165ea36a/go.mod h1:dDnQATFXCBOknvj6ZQuKfmDhbOWf3e8mtV+dPEfWJqs=
github.com/ONSdigital/log.go v1.0.1-0.20200805145532-1f25087a0744 h1:Wf92VblikYm5lv2fw9+No+2MUr/noAK/KI34qHQ6OHQ=
github.com/ONSdigital/log.go v1.0.1-0.20200805145532-1f25087a0744/go.mod h1:y4E9MYC+cV9VfjRD0UBGj8PA7H3wABqQi87/ejrDhYc=
github.com/ONSdigital/log.go v1.0.1 h1:SZ5wRZAwlt2jQUZ9AUzBB/PL+iG15KapfQpJUdA18/4=
github.com/ONSdigital/log.go v1.0.1/go.mod h1:dIwSXuvFB5EsZG5x44JhsXZKMd80zlb0DZxmiAtpL4M=
github.com/ONSdigital/log.go/v2 v2.0.5 h1:kl2lF0vr3BQDwPTAUcarDvX4Um3uE3fjVRfLoHAarBc=
github.com/ONSdigital/log.go/v2 v2.0.5/go.mod h1:PR7vXrv9dZKUc7SI/0toxBbStk84snmybBnWpe+xY2o=
github.com/facebookgo/freeport v0.0.0-20150612182905-d4adf43b75b9 h1:wWke/RUCl7VRjQhwPlR/v0glZXNYzBHdNUzf/Am2Nmg=
github.com/facebookgo/freeport v0.0.0-20150612182905-d4adf43b75b9/go.mod h1:uPmAp6Sws4L7+Q/OokbWDAK1ibXYhB3PXFP1kol5hPg=
github.com/fatih/color v1.9.0 h1:8xPHl4/q1VyqGIPif1F+1V3Y3lSmrq01EabUW3CoW5s=
github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU=
github.com/fatih/color v1.10.0 h1:s36xzo75JdqLaaWoiEHk767eHiwo0598uUxyfiPkDsg=
github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM=
github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
github.com/hokaccha/go-prettyjson v0.0.0-20190818114111-108c894c2c0e h1:0aewS5NTyxftZHSnFaJmWE5oCCrj4DyEXkAiMa1iZJM=
github.com/hokaccha/go-prettyjson v0.0.0-20190818114111-108c894c2c0e/go.mod h1:pFlLw2CfqZiIBOx6BuCeRLCrfxBJipTY0nIOF/VbGcI=
github.com/hokaccha/go-prettyjson v0.0.0-20210113012101-fb4e108d2519 h1:nqAlWFEdqI0ClbTDrhDvE/8LeQ4pftrqKUX9w5k0j3s=
github.com/hokaccha/go-prettyjson v0.0.0-20210113012101-fb4e108d2519/go.mod h1:pFlLw2CfqZiIBOx6BuCeRLCrfxBJipTY0nIOF/VbGcI=
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/justinas/alice v1.2.0 h1:+MHSA/vccVCF4Uq37S42jwlkvI2Xzl7zTPCN5BnZNVo=
github.com/justinas/alice v1.2.0/go.mod h1:fN5HRH/reO/zrUflLfTN43t3vXvKzvZIENsNEe7i7qA=
github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA=
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8=
github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.11 h1:FxPOTFNqGkuDUGi3H/qkUbQO4ZiBa2brKq5r0l8TGeM=
github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE=
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d h1:5PJl274Y63IEHC+7izoQE9x6ikvDFZS2mDVS3drnohI=
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
Expand All @@ -49,17 +54,23 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e h1:3G+cUijn7XD+S4eJFddp53Pv7+slrESplyjG25HgL+k=
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20200822124328-c89045814202 h1:VvcQYSHwXgi7W+TpUR6A9g6Up98WAHf3f/ulnJ62IyA=
golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b h1:uwuIcX0g4Yl1NC5XAz37xsr2lTtcqevgzYNVt49waME=
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd h1:xhmwyvizuTgC2qz7ZlMluP20uW+C3Rm0FD/WLDX8884=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210414055047-fe65e336abe0 h1:g9s1Ppvvun/fI+BptTMj909BBIcGrzQ32k9FNlcevOE=
golang.org/x/sys v0.0.0-20210414055047-fe65e336abe0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
8 changes: 4 additions & 4 deletions handlers/authentication.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

dphttp "github.com/ONSdigital/dp-net/http"
request "github.com/ONSdigital/dp-net/request"
"github.com/ONSdigital/log.go/log"
"github.com/ONSdigital/log.go/v2/log"
"github.com/gorilla/mux"
)

Expand All @@ -27,18 +27,18 @@ func CheckIdentity(handle func(http.ResponseWriter, *http.Request)) http.Handler
vars := mux.Vars(r)
logData := getLogData(ctx, r.URL.EscapedPath(), vars)

log.Event(ctx, "checking for an identity in request context", log.HTTP(r, 0, 0, nil, nil), logData)
log.Info(ctx, "checking for an identity in request context", log.HTTP(r, 0, 0, nil, nil), logData)

// just checking if an identity exists until permissions are being provided.
if !request.IsCallerPresent(ctx) {
log.Event(ctx, "no identity found in context of request", log.HTTP(r, 0, 0, nil, nil), logData)
log.Info(ctx, "no identity found in context of request", log.HTTP(r, 0, 0, nil, nil), logData)
http.Error(w, "unauthenticated request", http.StatusUnauthorized)
dphttp.DrainBody(r)
return
}

// The request has been authenticated, now run the clients request
log.Event(ctx, "identity found in request context, calling downstream handler", log.HTTP(r, 0, 0, nil, nil), logData)
log.Info(ctx, "identity found in request context, calling downstream handler", log.HTTP(r, 0, 0, nil, nil), logData)
handle(w, r)
})
}
Expand Down
2 changes: 1 addition & 1 deletion handlers/authentication_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"testing"

dprequest "github.com/ONSdigital/dp-net/request"
"github.com/ONSdigital/log.go/log"
"github.com/ONSdigital/log.go/v2/log"
. "github.com/smartystreets/goconvey/convey"
)

Expand Down
8 changes: 4 additions & 4 deletions handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package handlers
import (
"context"
"github.com/ONSdigital/dp-net/request"
"github.com/ONSdigital/log.go/log"
"github.com/ONSdigital/log.go/v2/log"
"net/http"
)

Expand Down Expand Up @@ -42,7 +42,7 @@ func DoCheckCookie(h http.Handler, key Key) http.Handler {
cookieValue, err := req.Cookie(key.Cookie())
if err != nil {
if err != http.ErrNoCookie {
log.Event(req.Context(), "unexpected error while extracting value from cookie", log.ERROR, log.Error(err),
log.Error(req.Context(), "unexpected error while extracting value from cookie", err,
log.Data{"cookie_key": key.Cookie()})
}
} else {
Expand All @@ -59,11 +59,11 @@ func ControllerHandler(controllerHandlerFunc ControllerHandlerFunc) http.Handler
locale := request.GetLocaleCode(r)
collectionID, err := request.GetCollectionID(r)
if err != nil {
log.Event(ctx, "unexpected error when getting collection id", log.ERROR, log.Error(err))
log.Error(ctx, "unexpected error when getting collection id", err)
}
accessToken, err := GetFlorenceToken(ctx, r)
if err != nil {
log.Event(ctx, "unexpected error when getting access token", log.ERROR, log.Error(err))
log.Error(ctx, "unexpected error when getting access token", err)
}
controllerHandlerFunc(w, r, locale, collectionID, accessToken)
}
Expand Down
16 changes: 8 additions & 8 deletions handlers/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
clientsidentity "github.com/ONSdigital/dp-api-clients-go/identity"
dphttp "github.com/ONSdigital/dp-net/http"
dprequest "github.com/ONSdigital/dp-net/request"
"github.com/ONSdigital/log.go/log"
"github.com/ONSdigital/log.go/v2/log"
)

type getTokenFromReqFunc func(ctx context.Context, r *http.Request) (string, error)
Expand All @@ -30,7 +30,7 @@ func identityWithHTTPClient(cli *clientsidentity.Client, getFlorenceToken, getSe
return func(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
ctx := req.Context()
log.Event(ctx, "executing identity check middleware")
log.Info(ctx, "executing identity check middleware")

florenceToken, err := getFlorenceToken(ctx, req)
if err != nil {
Expand All @@ -54,11 +54,11 @@ func identityWithHTTPClient(cli *clientsidentity.Client, getFlorenceToken, getSe

if authFailure != nil {
handleFailedRequest(ctx, w, req, statusCode, "identity client check request returned an auth error", authFailure, logData)
log.Event(ctx, "identity client check request returned an auth error", log.Error(authFailure), logData)
log.Error(ctx, "identity client check request returned an auth error", authFailure, logData)
return
}

log.Event(ctx, "identity client check request completed successfully invoking downstream http handler")
log.Info(ctx, "identity client check request completed successfully invoking downstream http handler")

req = req.WithContext(ctx)
h.ServeHTTP(w, req)
Expand All @@ -68,7 +68,7 @@ func identityWithHTTPClient(cli *clientsidentity.Client, getFlorenceToken, getSe

// handleFailedRequest adhering to the DRY principle - clean up for failed identity requests, log the error, drain the request body and write the status code.
func handleFailedRequest(ctx context.Context, w http.ResponseWriter, r *http.Request, status int, event string, err error, data log.Data) {
log.Event(ctx, event, log.Error(err), data)
log.Error(ctx, event, err, data)
dphttp.DrainBody(r)
w.WriteHeader(status)
}
Expand All @@ -80,7 +80,7 @@ func GetFlorenceToken(ctx context.Context, req *http.Request) (string, error) {
if err == nil {
florenceToken = token
} else if headers.IsErrNotFound(err) {
log.Event(ctx, "florence access token header not found attempting to find access token cookie")
log.Info(ctx, "florence access token header not found attempting to find access token cookie")
florenceToken, err = getFlorenceTokenFromCookie(ctx, req)
}

Expand All @@ -96,7 +96,7 @@ func getFlorenceTokenFromCookie(ctx context.Context, req *http.Request) (string,
florenceToken = c.Value
} else if err == http.ErrNoCookie {
err = nil // we don't consider this scenario an error so we set err to nil and return an empty token
log.Event(ctx, "florence access token cookie not found in request")
log.Info(ctx, "florence access token cookie not found in request")
}

return florenceToken, err
Expand All @@ -110,7 +110,7 @@ func getServiceAuthToken(ctx context.Context, req *http.Request) (string, error)
authToken = token
} else if headers.IsErrNotFound(err) {
err = nil // we don't consider this scenario an error so we set err to nil and return an empty token
log.Event(ctx, "service auth token request header is not found")
log.Info(ctx, "service auth token request header is not found")
}

return authToken, err
Expand Down
6 changes: 3 additions & 3 deletions http/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"context"

request "github.com/ONSdigital/dp-net/request"
"github.com/ONSdigital/log.go/log"
"github.com/ONSdigital/log.go/v2/log"
"github.com/justinas/alice"
)

Expand Down Expand Up @@ -132,14 +132,14 @@ func (s *Server) listenAndServeAsync() {
if len(s.CertFile) > 0 || len(s.KeyFile) > 0 {
go func() {
if err := s.Server.ListenAndServeTLS(s.CertFile, s.KeyFile); err != nil {
log.Event(nil, "http server returned error", log.Error(err))
log.Error(context.Background(), "http server returned error", err)
os.Exit(1)
}
}()
} else {
go func() {
if err := s.Server.ListenAndServe(); err != nil {
log.Event(nil, "http server returned error", log.Error(err))
log.Error(context.Background(), "http server returned error", err)
os.Exit(1)
}
}()
Expand Down
Loading

0 comments on commit cecbce0

Please sign in to comment.