Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
pino-std-serializers
Advanced tools
The pino-std-serializers package provides standard serializers for the Pino logging library. These serializers help in formatting various types of JavaScript objects and values into a more structured and readable format for logging purposes. This is particularly useful in applications where consistent log formats are necessary for debugging and monitoring.
req (HTTP request serializer)
Serializes HTTP request objects to log them in a structured format, including method, url, headers, and other relevant information.
const pino = require('pino');
const stdSerializers = require('pino-std-serializers');
const logger = pino({
serializers: {
req: stdSerializers.req
}
});
http.createServer((req, res) => {
logger.info({req}, 'request received');
res.end('hello world');
}).listen(3000);
res (HTTP response serializer)
Serializes HTTP response objects to capture and log status code, headers, and other response attributes.
const pino = require('pino');
const stdSerializers = require('pino-std-serializers');
const logger = pino({
serializers: {
res: stdSerializers.res
}
});
http.createServer((req, res) => {
res.on('finish', () => {
logger.info({res}, 'response sent');
});
res.end('hello world');
}).listen(3000);
err (Error serializer)
Provides a way to serialize error objects, including the message, stack trace, and other properties, which aids in debugging and error tracking.
const pino = require('pino');
const stdSerializers = require('pino-std-serializers');
const logger = pino({
serializers: {
err: stdSerializers.err
}
});
try {
throw new Error('Something went wrong');
} catch (err) {
logger.error({err}, 'error occurred');
}
While not a direct serializer library, morgan-json provides middleware to format HTTP request logs into JSON using Morgan, which can be seen as an alternative approach to logging HTTP requests compared to using pino-std-serializers with Pino.
This module provides a set of standard object serializers for the Pino logger.
exports.err(error)
Serializes an Error
like object. Returns an object:
{
type: 'string', // The name of the object's constructor.
message: 'string', // The supplied error message.
stack: 'string' // The stack when the error was generated.
}
Any other extra properties, e.g. statusCode
, that have been attached to the
object will also be present on the serialized object.
exports.mapHttpResponse(response)
Used internally by Pino for general response logging. Returns an object:
{
res: {}
}
Where res
is the response
as serialized by the standard response serializer.
exports.mapHttpRequest(request)
Used internall by Pino for general request logging. Returns an object:
{
req: {}
}
Where req
is the request
as serialized by the standard request serializer.
exports.req(request)
The default request
serializer. Returns and object:
{
id: 'string', // Default is an empty string. Attach a synchronous function
// to the input `request` that returns an identifier to have
// the value filled.
method: 'string',
url: 'string',
headers: Object,
remoteAddress: 'string',
remotePort: Number,
raw: Object // Non-enumerable, i.e. will not be in the output, original
// request object. This is available for subsequent serializers
// to use.
}
exports.res(response)
The default response
serializer. Returns an object:
{
statusCode: Number,
header: Array, // The list of headers to be sent in the response.
raw: Object // Non-enumerable, i.e. will not be in the output, original
// response object. This is available for subsequent serializers
// to use.
}
exports.wrapRequestSerializer(customSerializer)
A utility method for wrapping the default request serializer. This allows custom serializers to work with the already serialized object.
The customSerializer
accepts one parameter: the newly serialized request
object.
exports.wrapResponseSerializer(customSerializer)
A utility method for wrapping the default response serializer. This allows custom serializers to work with the already serialized object.
The customSerializer
accepts one parameter: the newly serialized response
object.
MIT License
FAQs
A collection of standard object serializers for Pino
The npm package pino-std-serializers receives a total of 5,338,728 weekly downloads. As such, pino-std-serializers popularity was classified as popular.
We found that pino-std-serializers demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.