expressjs / expressjs/morgan

Multiple morgan instances stubs out original start time

Open
#141 7 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
JavaScript
Stars
8.2k
Forks
565
Avg merge
3d 2h
Merged PRs (30d)
12

Description

Hello, I was looking to have multiple logs, the standard `process.stdout`, a `fileStreamRotate` and a `mongo` variant. I was looking to see if there would be any issues with a few being synchronous and a few being asynchronous. I didn't see much in the way of problems except the fact that the _startTime is set to undefined each time. Which could cause problems between multiple morgan instances.

I understand what I am about to write is an exaggeration and prob not recommended anyway, but I just wanted to point it out.

```js
var morgan = require("morgan");
var app = require("express")();

var stream1 = require("fs").createWriteStream("log.log");
var stream2 = process.stdout;

app.use(morgan("dev", { stream: stream1 }));
app.use((req, res, next) => { setTimeout(next, 2000); }); // Wait 2 seconds
app.use(morgan("dev", { stream: stream2 }));
app.use((req, res) => { res.send(); });

app.listen(3000);
```

As I said, this would be an extremely strange behaviour, but it does point out that both morgans record that the response time is ~8ms rather than over 2008ms

- Colin

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.