Comments (6)
@dtothefp side note, you should really not use bind
, it is super slow. Wrap the other call inside a function.
from pino.
I hacked around this by creating multiple Pino instances. Seems sloppy, wondering if there is a better way?
const serializers = pino.stdSerializers;
const name = APP_NAME;
if (LOG_ENV === 'development' || NODE_ENV === 'development') {
const pretty = pino.pretty();
pretty.pipe(process.stdout);
logger = pino({
name,
level: 'info',
serializers
}, pretty);
} else {
const noop = arg => arg;
const streams = [
{
level: 'warn',
path: path.join(LOG_DIRECTORY, `${APP_NAME}-warn.log`)
},
{
level: 'error',
path: path.join(LOG_DIRECTORY, `${APP_NAME}-error.log`)
}
];
logger = streams.reduce((acc, data) => {
const {level, path: logPath} = data;
const writeStream = fs.createWriteStream(logPath, {
flags: 'a',
encoding: 'utf8'
});
const inst = pino({
name,
level,
serializers
}, writeStream);
acc[level] = inst[level].bind(inst);
return acc;
}, {});
logger.info = noop;
}
from pino.
Hi @dtothefp
The "pino way" is to avoid any in-process overhead - only having one output stream is entirely deliberate - any other log processing should be done out-of-process
So what we'd need is
node app.js | pino-split-by-log-type
This ties into https://github.com/mcollina/pino#how-to-use-transports-with-pino
Currently, we don't have pino-split-by-log-type
, but if you're up for building it, here's some transports you can take inspiration from
- https://www.npmjs.com/package/pino-syslog
- https://www.npmjs.com/package/pino-elasticsearch
- https://www.npmjs.com/package/pino-socket
Let me know if you'd like to build it, and I'll support you (just open issues on your own repo and cc me (and Matteo) and we'll give feedback etc)
from pino.
@davidmarkclements thanks for the tips, if I get some time I will definitely try to work on this
from pino.
@mcollina good call, didn't know bind
was slower
from pino.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
from pino.
Related Issues (20)
- sonic boom is not ready yet HOT 2
- Error: unable to determine transport target for "@baselime/pino-transport" HOT 2
- Typescript: turn Level typings into an enum HOT 2
- [bug] logger.`setBindings` undefined when using esm exported pino HOT 2
- Accept log level env var as UPPER or LOWER case HOT 4
- Mutation of log inputs - (un)expected? HOT 8
- Recipe for email notifications? HOT 1
- getting the following message: pinoWebpackAbsolutePath is not defined HOT 2
- Endless issues of Error: Cannot find module '....\.next\server\vendor-chunks\lib\worker.js' HOT 2
- Print warning on changing log level when using multistream HOT 4
- The `pino.destination()` function is not defined on a browser (bug and/or documentation issue) HOT 1
- Drop support for printf style logging because once again i deployed logger.info(msg, obj) instead of logger.info(obj, msg) to prod and cant debug prod. HOT 2
- Using pino/browser for Cloudflare Workers HOT 2
- General Linux question: best command to view pino logs? HOT 4
- Simpler default logging output for objects HOT 8
- Recipe on how to downgrade error level for common errors? HOT 2
- default level:${defaultLevel} must be included in custom levels HOT 2
- Selectively omit fields of parameter object
- Log filename HOT 1
- pino logger bug when used webpack the worker has exited
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.