Comments (8)
from pino-pretty.
httpLogger.info(
{
method: req.method,
path: req.url,
referer: ref,
user: req.user,
},
'http request %s: %s',
req.method,
req.url,
);
This would output something like:
INFO [18:29:08.552]: http request GET: /index.htm
method: "GET"
path: "/index.htm"
referer: "http://localhost:3000/blog/ssfTKLgj58vc5fbYj/comment/ljrVbFMILabWQKV6o"
user: {
"id": "jWmre2l5sTAh3KfpQ",
"username": "smeijer",
"email": "[email protected]",
"ip_address": "127.0.0.1"
}
INFO [18:29:08.552]: http request GET: /favicon.ico
method: "GET"
path: "/favicon.ico"
referer: "http://localhost:3000/blog/ssfTKLgj58vc5fbYj/comment/ljrVbFMILabWQKV6o"
user: {
"id": "jWmre2l5sTAh3KfpQ",
"username": "smeijer",
"email": "[email protected]",
"ip_address": "127.0.0.1"
}
INFO [18:29:08.552]: http request GET: /logo.png
method: "GET"
path: "/logo.png"
referer: "http://localhost:3000/blog/ssfTKLgj58vc5fbYj/comment/ljrVbFMILabWQKV6o"
user: {
"id": "jWmre2l5sTAh3KfpQ",
"username": "smeijer",
"email": "[email protected]",
"ip_address": "127.0.0.1"
}
Which is a bit much and hard to scan. We don't always need that detailed info in the console while developing. If I need the details, I'll make sure to hit a breakpoint. Simply logging the formatted message, would be more informative. I see the console more as a global overview of data streams. And use the debugger to dive into details.
So reducing that output to something like this (in NODE_ENV !== production
), would be very helpful:
INFO [18:29:08.552]: http request GET: /index.htm
INFO [18:29:08.552]: http request GET: /favicon.ico
INFO [18:29:08.552]: http request GET: /logo.png
Also, if info messages can be logged as a single line, errors would have less chance to be missed. I now get so much data at certain moments, that it's easy to miss the errors.
from pino-pretty.
from pino-pretty.
I understand, and I agree.
But piping to pino-pretty
is done willingly, correct? At least, I don't use pino-pretty on production. I only use it to format the messages during development, and than the suggestion I posted above would help.
from pino-pretty.
Some additional context, an abstracted version of my logger configuration:
import pino from 'pino';
import noir from 'pino-noir';
import pico from 'picoid';
const base = {
sid: pico(),
hostname: process.env.HOST_NAME,
appname: process.env.APP_NAME,
instance: ~~process.env.INSTANCE_ID,
release: process.env.VERSION,
};
const redact = noir([...], '***');
const prettyPrint = process.env.NODE_ENV === 'development'
? {
colorize: true,
levelFirst: true,
translateTime: 'HH:MM:ss.l',
ignore: 'sid,appname,instance,release,ns,headers',
}
: false;
const logger = pino({
level: process.env.LOG_LEVEL || 'info',
serializers: redact,
base,
prettyPrint,
});
from pino-pretty.
Redaction is embedded in pino now, check out http://getpino.io/#/docs/redaction.
I’d be happy to support more customization to pino-pretty tbh, would you like to send a PR?
from pino-pretty.
I'm +1 on this. Would be a great way to get an overview of the logs in a single terminal window, right now it can become quite few log lines if the log lines has quite many attributes
from pino-pretty.
Would you like to send.a PR?
from pino-pretty.
Related Issues (20)
- Test files included in release tarball and `module.exports` based on content of directory are messing with `esbuild` bundler HOT 8
- Refactor causes breaking change HOT 1
- [Request] Allow overriding timezone HOT 2
- Can't use custom messageFormat function HOT 1
- Selective formatting of Pino output while preserving third-party output HOT 5
- Can't use default when dynamic import for TS module resolution: node16 HOT 4
- Documentation shows colorization functions, but they don't seem to exist or work HOT 1
- Function.prototype.toString requires that 'this' be a Function HOT 2
- Logs missing in Jest tests HOT 5
- Couldn't log chinese character correctly HOT 1
- How to use transport with nestjs? HOT 1
- How do I change the time, I want it to carry the date instead of just the time HOT 1
- Remove reliance on worker_thread to enable working with wrangler (CF worker) HOT 1
- LevelName whitespace alignment issue HOT 3
- Pino-pretty doesn't work if timestamp is changed HOT 2
- Cannot find type definition file for pino-pretty while running npm run lint HOT 5
- PinoPretty.customPrettifiers() lacks arguments declared in type PinoPretty.Prettifier HOT 1
- Time zone does not match HOT 2
- `sync` doesn't work HOT 2
- Logging Error-like object causes crash
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-pretty.