Pino (pinojs) only logging some HTTP request

1.1k Views Asked by At

I am trying to add logging with pino to an existing node.js web application, that uses express.js and Postgresql. However, some HTTP post request are not being logged. It seems to only happen with HTTP post request responding with a redirect. It also only happens then requesting by Safari. The problem does not occur then using Chrome or curl.

I am produced a minimal example here under, that reproduces the problem. As in my main project it does reproduce the problem when using Safari on my laptop, but not when using Chrome or curl. If I remove the usage of connect-pg-simple the problem disappears.

No error message what so ever is given.

import { default as express } from 'express'
import { default as pinoHttp } from 'pino-http'
import { default as session } from 'express-session';
import { default as sessionStore } from 'connect-pg-simple';

import { default as pg } from 'pg';
const Pool = pg.Pool
const pool = new Pool()

const reqLogger = pinoHttp({
    level: 'info',
    enabled: true
})

const app = express()

app.use(session({
    secret: 'secret',
    name: 'sessionId',
    resave: false,
    rolling: true,
    saveUninitialized: true,
    store: new (sessionStore(session))({
        pool: pool
    }),
    cookie: {
        secure: 'auto',
        maxAge: 30 * 24 * 60 * 60 * 1000
    }
}))

app.use(reqLogger)

app.get('/', (req, res, next) => {
    const html = `
        <form method="POST" action="/">
            <div>
                <label for="floatingInput">Username</label>
                <input name="username" type="text" id="floatingInput">
            </div>
            <div>
                <label for="floatingPassword">Password</label>
                <input name="password" type="password" id="floatingPassword">
            </div>

            <button type="submit">Log in</button>
        </form>`
    res.send(html)
})

app.post('/', (req, res, next) => {
    res.redirect('/')
})

app.listen(8081, () => {
    console.log('Server running')
})
0

There are 0 best solutions below