git clone https://github.com/pinojs/pinojs
cd pinojs
npm install
npm start
pinojs / pino-syslog Goto Github PK
View Code? Open in Web Editor NEW๐ฒ A transport for reformatting pino logs into standard syslog format
๐ฒ A transport for reformatting pino logs into standard syslog format
how can I append to linux var/logs?
Hi!
I made such a configuration as you described in the example:
import pino from 'pino'
const transport = pino.transport({
pipeline: [
{
target: 'pino-syslog',
level: 'info',
options: {
modern: false,
appname: process.env.npm_package_name,
enablePipelining: true,
}
},
{
target: 'pino-socket',
options: {
mode: 'tcp',
address: '127.0.0.1',
port: 8001
}
}
]
})
pino(transport)
But I don't get any logs.
I spent a lot of time debugging this issue. And here's what I found out:
Your plugin (pipo-syslog) does not transmit any data further down the pipeline. To be sure of this, I wrote my transport and replaced pino-socket:
const tls = require('tls')
const { pipeline, Writable } = require('stream')
const build = require('pino-abstract-transport')
module.exports = function createTransport(opts) {
return build(
function (source) {
console.log('createTransport', opts) // Console-1
source.on('error', console.error)
source.on('close', () => console.info('source close'))
source.on('data', function (data) {
console.log('source data', data) // Console-2
stream.write(JSON.stringify(data))
})
const socket = tls.connect(opts, () => {})
socket.on('data', function (data) {
console.info('socket data', data)
})
socket.on('error', console.error)
socket.on('close', console.info)
const stream = new Writable({
open: true,
autoDestroy: true,
close() {
socket.end()
},
write(data, encoding, callback) {
console.log('tls.connect write', data.toString()) // Console-3
socket.write(data)
callback()
},
})
return stream
},
{
enablePipelining: true,
}
)
}
After starting the logger, I only see the message of Console-1
. When I try to send data to the logger, nothing happens. I don't see a single message.
But if I comment out your plugin in the configuration, then I will receive all messages from the logger (without the transformations that your plugin does, since it is disabled).
You need to fix the data transfer to the next pipeline.
Hope you can help me solve this problem!
Currently, transform doesn't add a newline to the end of the log. If it's something required by syslog spec can we add this feature by the flag?
If you agree I can prepare a PR with this feature.
Cheers,
Piotr
Hi,
In file lib/rfc3164.js", I see those lines:
const zeroReg = /0/
const tstamp = moment(data.time).tz(options.tz).format('MMM DD HH:mm:ss').replace(zeroReg, ' ')
On Wed Jan 30 13:49:34 CET 2019, the tsstamp will be equal to
"Jan 3 12:43:12" instead of expected
"Jan 30 12:43:12"
The problem is that it replaces any zero in the string while the expected behavior for RFC3164 is to replaced only the leading zero of the day!
So, I guess it will also fail for month equals october...
This transform works only if an app is executed directly from the node. Because npm/yarn adds own non-json logs to the output it throws SyntaxError: Unexpected end of JSON input
.
Maybe we could simply detect if the log comes from pino and if not just ignore it?
Thanks,
Piotr
I was unable to use pipelining to send syslog to a running promtail instance; I used the example from the README without any luck.
Did I miss something?
Thanks
I'd like to format the APP-NAME
field in the syslog message like this: ${appName}.${loggerName}
. Right now the pino-syslog only supports static values as the appname. Does supporting dynamic values sound good?
Is the transport available with Pino v8?
I'm trying to use it wit Fastify as described in docs
const fastify = Fastify({
disableRequestLogging: true,
logger: {
enabled: true,
level: 'info',
transport: {
target: 'pino-syslog',
},
},
})
but unlike pino-pretty
, there is no output.
According to pino docs this is a Legacy transport and should work at least with pipelines - but not for me.
How to configure pino redact with this transport?
The moment
library is effectively deprecated. We should be able to replace it with luxon
.
The options described in an external configuration file (--config flag) are overriden by the default internal config values.
The final option object should be constructed just before the transport assignment block:
const options = Object.assign({}, defaults, jsonOptions, args);
I would like to create a PR but I can't push a branch on this repo.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.