Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
@dotcom-reliability-kit/middleware-log-errors
Advanced tools
Express middleware to consistently log errors
Express middleware to consistently log errors. This module is part of FT.com Reliability Kit.
Install @dotcom-reliability-kit/middleware-log-errors
as a dependency:
npm install --save @dotcom-reliability-kit/middleware-log-errors
Include in your code:
import createErrorLogger from '@dotcom-reliability-kit/middleware-log-errors';
// or
const createErrorLogger = require('@dotcom-reliability-kit/middleware-log-errors');
createErrorLogger
The createErrorLogger
function can be used to generate Express middleware which logs errors to the console and Splunk via n-logger. It must be added to your Express app after all your application routes:
const app = express();
// App routes go here
app.use(createErrorLogger());
This will automatically serialize error objects and log them along with a serialized HTTP request which lead to the error being thrown. The information logged looks like this:
{
event: 'HANDLED_ERROR',
error: {
// See `@dotcom-reliability-kit/serialize-error` (linked above)
// for information about the logged properties
},
request: {
// See `dotcom-reliability-kit/serialize-request` (linked above)
// for information about the logged properties
},
app: {
name: 'example-app',
region: 'EU'
}
}
Config options can be passed into the createErrorLogger
function as an object with any of the keys below.
app.use(createErrorLogger({
// Config options go here
}));
options.includeHeaders
An array of request headers to include in the serialized request object. This must be an Array
of String
s, with each string being a header name. It's important that you do not include headers which include personally-identifiable-information, API keys, or other privileged information. This defaults to ['accept', 'content-type']
. This option gets passed directly into dotcom-reliability-kit/serialize-request
which has further documentation.
serializeRequest(request, {
includeHeaders: [
'accept',
'content-length',
'content-type',
'user-agent'
]
});
See the central contributing guide for Reliability Kit.
Licensed under the MIT license.
Copyright © 2022, The Financial Times Ltd.
FAQs
Express middleware to consistently log errors
The npm package @dotcom-reliability-kit/middleware-log-errors receives a total of 208 weekly downloads. As such, @dotcom-reliability-kit/middleware-log-errors popularity was classified as not popular.
We found that @dotcom-reliability-kit/middleware-log-errors demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 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
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.