Cabin
:evergreen_tree: Cabin is the best self-hosted JavaScript and Node.js logging service. Made for @forwardemail.
Install / Use
/learn @cabinjs/CabinREADME
Table of Contents
- Foreword
- Quick Start
- Features
- Send Logs to an HTTP endpoint
- Send Logs to Slack
- Send Logs to Sentry
- Send Logs to Datadog
- Send Logs to Papertrail
- Suppress Logger Data
- Install
- Usage
- Options
- Display Metadata and Stack Traces
- Related
- License
Foreword
Please defer to Axe's Foreword for more insight.
Cabin is a layer on top of Axe that provides automatic logging for route middleware requests and errors.
Quick Start
npm install express axe cabin signale
const express = require('express');
const Axe = require('axe');
const Cabin = require('cabin');
const app = express();
const { Signale } = require('signale');
// initialize a new instance of Axe (see below TODO's that appeal to you)
const logger = new Axe({
logger: new Signale()
});
// TODO: if you want to send logs to an HTTP endpoint then follow this guide:
// https://github.com/cabinjs/axe/#send-logs-to-http-endpoint
// TODO: if you want to send logs to Slack then follow this guide:
// https://github.com/cabinjs/axe/#send-logs-to-slack
// TODO: if you want to send logs to Sentry then follow this guide:
// https://github.com/cabinjs/axe/#send-logs-to-sentry
// TODO: if you want to send logs to Datadog then follow this guide:
// https://github.com/cabinjs/axe/#send-logs-to-datadog
// TODO: if you want to send logs to Papertrail then follow this guide:
// https://github.com/cabinjs/axe/#send-logs-to-papertrail
// TODO: if you want to suppress specific log metadata then follow this guide:
// https://github.com/cabinjs/axe/#suppress-logger-data
// initialize a new instance of Cabin with an Axe logger instance
const cabin = new Cabin({ logger });
//
// initialize route logging middleware
//
// NOTE: this will automatically log route middleware requests and errors
//
app.use(cabin.middleware);
app.get('/', (req, res, next) => res.send('OK'));
// start the server
app.listen(3000);
curl http://localhost:3000
Features
Security, Privacy, and Business Focused
Cabin will automatically detect and mask the following list of extremely sensitive types of data in your logs:
- [1600+ Sensitive Field Names][sensitive-fields]
- Credit Card Numbers<sup>*</sup>
- [BasicAuth Headers][basicauth-headers]
- Social Security Numbers
- [JSON Web Tokens ("JWT")][jwt-tokens]
- API Keys, CSRF Tokens, and Stripe Tokens
- Passwords, Salts, and Hashes
- Bank Account Numbers and Bank Routing Numbers
<small><sup>*</sup>Credit card numbers from the following providers are automatically detected and masked: Visa, Mastercard, American Express, Diners Club, Discover, JCB, UnionPay, Maestro, Mir, Elo, Hiper, Hipercard</small>
Reduce Disk Storage Costs
Reduce your disk storage costs through Cabin's automatic conversion of Streams, Buffers, and ArrayBuffers to simplified, descriptive-only objects that otherwise would be unreadable (and obviously pollute your log files and disk storage).
Before:
{
"request": {
"body": {
"file": {
"type": "Buffer",
"data": [
76,
111,
114,
101,
109,
32,
105,
112,
115,
117,
109,
32,
100,
111,
108,
111,
114,
32,
115,
105,
116,
'...'
]
}
}
}
}
After
{
"request": {
"body": {
"file": {
"type": "Buffer",
"byteLength": 2787
}
}
}
}
Cross-Platform and Cross-Browser Compatible
Cabin works with the most popular Node.js HTTP frameworks (e.g. [Express][] and [Koa][]), request body handling packages (e.g. [multer][] and [body-parser][]), and the [passport][] authentication framework.
It supports Node v18+ and modern browsers out of the box (its browser-ready bundle is only 20 KB).
npx browserslist
and_chr 107
and_ff 106
and_qq 13.1
and_uc 13.4
android 107
chrome 107
chrome 106
chrome 105
edge 107
edge 106
edge 105
firefox 106
firefox 105
firefox 102
ios_saf 16.1
ios_saf 16.0
ios_saf 15.6
ios_saf 15.5
ios_saf 14.5-14.8
kaios 2.5
op_mini all
op_mob 64
opera 91
opera 90
safari 16.1
safari 16.0
safari 15.6
samsung 18.0
samsung 17.0
Send Logs to an HTTP endpoint
See the Quick Start section above and our guide at https://github.com/cabinjs/axe/#send-logs-to-http-endpoint.
Send Logs to Slack
See the Quick Start section above and our guide at https://github.com/cabinjs/axe/#send-logs-to-slack.
Send Logs to Sentry
See the Quick Start section above and our guide at https://github.com/cabinjs/axe/#send-logs-to-sentry.
Send Logs to Datadog
See the Quick Start section above and our guide at https://github.com/cabinjs/axe/#send-logs-to-datadog.
Send Logs to Papertrail
See the Quick Start section above and our guide at https://github.com/cabinjs/axe/#send-logs-to-papertrail.
Suppress Logger Data
See the Quick Start section above and our guide at https://github.com/cabinjs/axe/#suppress-logger-data.
Install
Note that as of v11.0.0 Cabin requires a peer dependency of [Axe][] to be installed.
[npm][]:
npm install cabin axe
Usage
Logging
const Cabin = require('cabin');
const cabin = new Cabin({
// ... see the Quick Start and Options sections
});
cabin.info('hello world');
cabin.error(new Error('oops!'));
Route Logging Middleware
app.use(cabin.middleware);
See either the Node or Browser instructions below for further route middleware usage and proper setup.
Node
The examples below show how to use Cabin in combination with [Axe][], [Signale][] (instead of
console), and how to add an accurateX-Response-Timeresponse time metric to your logs and response headers automatically.
Koa
-
Install required and recommended dependencies:
npm install koa cabin signale request-received koa-better-response-time koa-better-request-id -
Implement the example code below (also found here):
const Koa = require('koa'); const Cabin = require('cabin'); const Router = require('koa-router'); const requestReceived = require('request-received'); const responseTime = require('koa-better-response-time'); const requestId = require('koa-better-request-id'); const { Signale } = require('signale'); const app = new Koa(); const router = new Router(); const cabin = new Cabin({ logger: new Signale() }); // adds request received hrtime and date symbols to request object // (which is used by Cabin internally to add `request.timestamp` to logs app.use(requestReceived); // adds `X-Response-Time` header to responses app.use(responseTime()); // adds or re-uses `X-Request-Id` header app.use(requestId()); // use the cabin middleware (adds request-based logging and helpers) app.use(cabin.middleware); // add your user/session management middleware here (e.g. passport) // ... // an
