Comments (11)
I'd like this option as well.
The suggested 11.11.111.111 - GET /url/path - Status Code: 200
format would be preferred in any configuration instead of the default request completed
message, however i'd also add an option to remove details of req
and res
unless I opt into getting them for specific endpoints.
This code looks easy enough to fork though, so I won't wait around too long for it.
from pino-http.
Might customSuccessMessage
be a solution for you?
Similar to:
const requestLogger = require("express-pino-logger")({
customSuccessMessage: function (res) {
return `${res.req.ip} - ${res.req.originalMethod} ${res.req.originalUrl} - ${res.statusCode}`;
},
});
(See
Line 54 in 4d1c320
from pino-http.
How about using pino-pretty in the following way?
const options = {
name: "example",
...(process.env.NODE_ENV !== "production"
? {
prettyPrint: {
ignore: 'req,res,responseTime',
messageFormat: (log, messageKey, levelLabel) => {
if (log.req) return `${log.responseTime}ms - ${log.msg} - ${log.req.url}`;
return `${log.msg}`;
}
}
}
: null)
};
from pino-http.
from pino-http.
I'm -1 in removing the lines from pino-http for formatting reasons. I'm happy to review a PR that make things more flexible here.
from pino-http.
Okay I did some digging and I think what I am looking for is something like this. I think it would be possible by using the stream like you did to manipulate the logging format. Is that true? If so I guess it wouldn't apply to the pino-http
module.
from pino-http.
I couldn't get pino-http-print
to work at all.
Attempt 1:
import express from "express";
import pino from "pino";
import expressPino from "express-pino-logger";
import pinoHttpPrint from "pino-http-print";
const log = pino({
prettyPrint: {
translateTime: "SYS:yyyy-mm-dd HH:MM:ss.l",
},
});
const app = express();
app.use(expressPino(pinoHttpPrint()));
Attempt 2:
app.use(expressPino(pinoHttpPrint({ all: true })));
Attempt 3:
app.use(
expressPino({
logger: log,
stream: pinoHttpPrint({ all: true }),
}),
);
Anyway, this is probably the wrong place for this comment but instead of starting new issues that I don't really care about I figured I'd just leave it here, fork pino-http
and do what I want just for my own projects.
This seems like a really good logger but it's just too bad that I have to compose 3 different packages together just to get some useful Express logging without all of the req
/res
diarrhea.
from pino-http.
I couldn't get
pino-http-print
to work at all.
An update was released for pino-http-print
right after this that added some options, I suggest you check it out again.
The difference is that the pino-http-print
module returns a factory instead of a print stream directly. So you have to call it again to get a stream.
My current setup:
const express = require("express");
const pino = require('pino');
const pinoPrint = require('pino-http-print');
const expressPino = require('express-pino-logger')
const prettyPrintFactory = pinoPrint({
all: true,
relativeUrl: true,
translateTime: 'SYS:standard',
});
const prettyPrint = prettyPrintFactory();
const log = pino(prettyPrint);
const app = express();
app.use(expressPino(prettyPrint));
// OR reuse existing pino instance instead
// app.use(expressPino({logger: log}));
app.get('/test', (req, res) => {
res.send('OK');
})
app.listen(3000, () => {
log.info('Listening now...');
});
Output:
[2020-02-16 18:52:07.083 +0530] INFO (22235 on lg-gram-elementary): Listening now...
[2020-02-16 18:52:11.892 +0530] GET /test 200
[2020-02-16 18:52:12.007 +0530] GET /favicon.ico 404
from pino-http.
@waynebloss to be clear, there is a much simpler pattern for this http://getpino.io/#/docs/pretty?id=pretty-printing
you pipe the JSON output to a prettifer, that's it.
from pino-http.
you pipe the JSON output to a prettifer, that's it.
pino-http-print
also works as a command. Equivalent example would be:
node index.js | pino-http-print -a -r -t 'SYS:standard'
with the below index.js
file.
// index.js
const express = require("express");
const expressPino = require('express-pino-logger')
const app = express();
app.use(expressPino());
Though setting up pino with a prettifier conditionally in dev environment is also pretty convenient.
@davidmarkclements Would a pino-http-print example in the pretty printing section be a good idea for the docs? I know a few people who migrated from morgan to pino/express-pino but had a hard time setting up pretty printing for dev environments for request logs.
from pino-http.
I'd like to have that too... The pino-http-print
does not work for me...
I'll adopt the @clemenspeters solution but it will be a better if I can have req and res already serialized as parameters there (there is no way to access responseTime
in the customSuccessMessage
function...).
This solution is actually a workaround and if I want to have only that message I have to put req and res to null in the serializers...
from pino-http.
Related Issues (20)
- reading 'stringifySym' doesn't work with next.js HOT 5
- IncomingMessage and ServerMessage typings are too specific HOT 2
- Updating for v10 HOT 2
- How can I put context in request completed log (when autoLogging is true) ?
- Release next version HOT 1
- node:util module not found HOT 6
- nestedKey now working properly HOT 1
- Message "request completed" when request not completed HOT 1
- `wrapChild` doesn't pass on options to the created child logger as expected HOT 3
- How best to handle extending req.log? HOT 6
- customProps causes TypeError: logger[stringifySym] is not a function HOT 17
- Type 'Opts' does not satisfy the constraint 'string'.ts(2344) HOT 5
- TypeScript error when using customLevels on pino parent instance HOT 1
- Updating for v9 HOT 3
- Log req only on 1st log from the request HOT 2
- Unable to remove whole req object from response logs HOT 3
- Undocumented Breaking Changes for 9.0.0 HOT 1
- How to inject request to the HttpLogger in the express middleware example? HOT 1
- Broken with h3 HOT 4
- CLI not installing HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pino-http.