Skip to content

Structured logs for HTTP 404 endpoints #2011

@ahmetb

Description

@ahmetb

Hello,

I realized if a client requests a non-existing endpoint (say, /foo) no record of this appears in any structured form (i.e. logfmt/json). If you leave the Apache access.log (CLF) logs on, an entry appears there, and that is all:

172.17.0.1 - - [19/Oct/2016:02:22:16 +0000] "GET /foo HTTP/1.1" 404 19 "" "curl/7.49.1"

I think there should be some structured log entry for those

  • who want to unify all the logs coming out of registry in structured form (like below)
  • and therefore disabling CLF entries

Ideally I'd love to see this log from a nonexisting endpoint:

time="2016-10-19T02:24:06.460645555Z" level=info msg="response completed" environment=development go.version=go1.6.3 http.request.host="localhost:5000" http.request.id=060b3c1c-02df-4f3c-91a1-74d4bfef70a8 http.request.method=GET http.request.remoteaddr="172.17.0.1:43418" http.request.uri="/foo" http.request.useragent="curl/7.49.1" http.response.contenttype="application/json; charset=utf-8" http.response.duration=1.477627ms http.response.status=404 http.response.written=19 instance.id=082c15c4-ddf9-4b60-8689-95d4fe8852f5 service=registry version=v2.5.0-rc.1-180-g8234784

But when I look at app.go I see this:

        status, ok := ctx.Value("http.response.status").(int)
        if ok && status >= 200 && status <= 399 {
            ctxu.GetResponseLogger(ctx).Infof("response completed")
        }

this was added in 54f7e5d but I am not sure if this code path gets invoked on routes that are not handled at all, because later in that file there is a log message response completed with error that gets printed when there is an error from an endpoint...

Any opinions?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions