Open tytremblay opened 1 year ago
I think the following should work:
import pino from 'pino';
const logger = pino({
level: 'info',
transport: {
targets: [
{
level: 'trace',
target: 'pino-socket',
options: {
unixsocket: '/dev/log',
mode: 'tcp',
},
},
{ level: 'trace', target: 'pino-pretty', options: {} },
],
},
});
logger.info(`pino logger instantiated `);
export { logger };
Note that this shows a bug here, as 'tcp'
should likely be set if unixsocket
is passed through.
@tytremblay would you like to send a PR with the fix?
I'll give it a shot. In the meantime, I found this article that suggest my application should log to stdout
or stderr
and let the system its running on pipe that output to syslog if they so desire. My sysadmin agrees, so we've gone with that approach for now.
Logs are a stream, and it behooves everyone to treat them as such. Your programs should log to stdout and/or stderr and omit any attempt to handle log paths, log rotation, or sending logs over the syslog protocol. Directing where the program’s log stream goes can be left up to the runtime container: a local terminal or IDE (in development environments), an Upstart / Systemd launch script (in traditional hosting environments), or a system like Logplex/Heroku (in a platform environment).
I'll give it a shot. In the meantime, I found this article that suggest my application should log to
stdout
orstderr
and let the system its running on pipe that output to syslog if they so desire. My sysadmin agrees, so we've gone with that approach for now.
Yes, that is the Pino way. See also https://www.nearform.com/blog/pino-the-fastest-node-js-logger-for-production/ (https://www.npmjs.com/package/@sematext/logagent).
The Issue
I'm trying to use
pino-socket
as a transport to log to syslog via/dev/log
on my Ubuntu 22.04 system using node 18.Here's the output I see in my console:
And of course no logs show up when I run
tail -f /var/log/syslog | grep pino
winston-syslog
seems to workBut I would much rather use
pino
I get this line in
/var/log/syslog
:The Ask
I'm sure I'm doing something wrong. Could you please provide an example?