Skip to content

BuffLog middleware INFRA-382 #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 8, 2020
Merged

BuffLog middleware INFRA-382 #13

merged 4 commits into from
Apr 8, 2020

Conversation

erickhun
Copy link
Collaborator

@erickhun erickhun commented Apr 7, 2020

In order to replace the previous @bufferapp/middleware

  • Add getLogger to be able to use the pino instance
  • Ddd the middleware() function (use pino-http under the hood)

Usage:

const app = express();
app.use(BuffLog.middleware())

or if we want to use the logger instance instead to personalise how the middleware works :

const app = express();
const middlewareLogger = require('pino-http')({
  logger: bufflog.getLogger(),
 // ... options
})
app.use(middlewareLogger)

the output looks like this:

{
    "dd": {
        "span_id": "6047504131036872311",
        "trace_id": "6047504131036872311"
    },
    "level": 200,
    "message": "request completed",
    "req": {
        "headers": {
            "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
            "accept-encoding": "gzip, deflate, br",
            "accept-language": "en-US,en;q=0.9,fr;q=0.8,zh-TW;q=0.7,zh;q=0.6",
            "cache-control": "max-age=0",
            "connection": "keep-alive",
            "host": "localhost:4000",
            "if-none-match": "W/\"11-IkjuL6CqqtmReFMfkkvwC0sKj04\"",
            "sec-fetch-dest": "document",
            "sec-fetch-mode": "navigate",
            "sec-fetch-site": "cross-site",
            "sec-fetch-user": "?1",
            "upgrade-insecure-requests": "1",
            "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36"
        },
        "id": 1,
        "method": "GET",
        "remoteAddress": "::1",
        "remotePort": 61841,
        "url": "/"
    },
    "res": {
        "headers": {
            "etag": "W/\"11-IkjuL6CqqtmReFMfkkvwC0sKj04\"",
            "x-powered-by": "Express"
        },
        "statusCode": 304
    },
    "responseTime": 10,
    "time": 1586254897546,
    "v": 1
}

There was also many stats calculated in the previous loggers. I feel like those should be aimed to be in the APM tracking instead of the logs.

@esclapes up for a review?

@erickhun erickhun requested a review from esclapes April 7, 2020 10:02
@erickhun erickhun changed the title BuffLog midleware BuffLog middleware Apr 7, 2020
Copy link

@esclapes esclapes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great @erickhun I have suggested a small change for extra flexibility (when needed), but this looks good to me! 🌮 🌮

@erickhun erickhun requested a review from colinscape April 8, 2020 08:31
Copy link
Contributor

@colinscape colinscape left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, this looks great to me! 👍

@erickhun erickhun merged commit fb71770 into master Apr 8, 2020
@erickhun erickhun deleted the task/return-logger branch April 8, 2020 15:04
@erickhun erickhun changed the title BuffLog middleware BuffLog middleware INFRA-382 Apr 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants