-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Any way to return "msg" (in prod) as JSON? #132
Comments
Can you give me an example / code snippet of what you're trying to do and the expected vs. actual output? I would definitely accept a PR for sure man or fix this myself for you. Just need to know specifically what you mean |
Thanks dude! Example prod log entry sent to DataDog:
Pino + CabinJS thangz:
Desired behavior:In the log output, you'll notice that everything at the "msg" value is stringified JSON. I'm wondering if there's a way to return all of this - in prod - as pure and total JSON, since tools like DataDog and GrayLog are friendly to JSON, and would automatically detect and extract the key/value pairs as labels/fields. I know it's absolutely ANTITHETICAL to the concept of the apache log standards, but...I'm shamelessly asking :) |
Have you tried specifying a custom https://github.com/cabinjs/cabin#options |
I've read through that - not to be a nag or a baby - but I'm just trying to figure out (maybe with an example) what a custom function would look like? I'm actually more confused now, since the code I see is this:
but it looks like I'm getting WAY more than that in my logs to DataDog...sorry for sounding illiterate. |
That code returns a string as the message. If you want an object, you could do something like: function message(options) {
const { req, res, ctx } = options;
const creds = auth(req);
const startTime = getStartTime(req);
return {
ip: ctx ? ctx.ip : req.ip,
creds: creds ? creds.name : '-',
clf_date: clfDate(startTime),
method: req.method,
url: req.url,
http_version: req.httpVersionMajor + '.' + req.httpVersionMinor,
status_code: res.statusCode,
content_length: res.getHeader('content-length') || '-'
};
}
// ...
const cabin = new Cabin({
capture: false,
axe: {
logger: NODE_ENV === 'production' ? pinoProd : pinoDev,
},
message // <--
}); |
Pino itself might be stringifying the message, I am unsure. |
Hey @niftylettuce!
We're using DataDog, and it's friendly to "natural JSON" a la
pino
.I've read the documentation and understand that whatever is returned @ the
msg
property has to be a string, and that it complies with the apache-friendly log RFCs, because you're a man of taste and experience.BUT, is there any way to get JSON back? Or maybe have the choice between apache-friendly and JSON?
Thanks for all your work, man!
_Armen
The text was updated successfully, but these errors were encountered: