Cabin is the best self-hosted JavaScript and Node.js logging service.
Supports Node v18+, Browser Environments, Express, Koa, and Lad
Cabin is compatible with Sentry, Airbrake, Papertrail, Loggly, and Bugsnag.
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.
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
Cabin will automatically detect and mask the following list of extremely sensitive types of data in your logs:
*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
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
}
}
}
}
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
See the Quick Start section above and our guide at https://github.com/cabinjs/axe/#send-logs-to-http-endpoint.
See the Quick Start section above and our guide at https://github.com/cabinjs/axe/#send-logs-to-slack.
See the Quick Start section above and our guide at https://github.com/cabinjs/axe/#send-logs-to-sentry.
See the Quick Start section above and our guide at https://github.com/cabinjs/axe/#send-logs-to-datadog.
See the Quick Start section above and our guide at https://github.com/cabinjs/axe/#send-logs-to-papertrail.
See the Quick Start section above and our guide at https://github.com/cabinjs/axe/#suppress-logger-data.
Note that as of v11.0.0 Cabin requires a peer dependency of [Axe][] to be installed.
[npm][]:
npm install cabin axe
const Cabin = require('cabin');
const cabin = new Cabin({
// ... see the Quick Start and Options sections
});
cabin.info('hello world');
cabin.error(new Error('oops!'));
app.use(cabin.middleware);
See either the Node or Browser instructions below for further route middleware usage and proper setup.
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.
sh
npm install koa cabin signale request-received koa-better-response-time koa-better-request-id
```js 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 example home page route router.get('/', ctx => { ctx.logger.info('visited home page'); ctx.body = 'hello world'; });
// this assumes that you are using passport which
// exposes ctx.logout to log out the logged in user
router.get('/logout', ctx => {
ctx.logger.warn('Logged out');
ctx.logout();
ctx.redirect('/');
});
app.use(router.routes()); app.use(router.allowedMethods());
app.listen(3000, () => { cabin.info('app started'); }); ```
sh
npm install express cabin signale request-received response-time express-request-id
```js const express = require('express'); const Cabin = require('cabin'); const requestReceived = require('request-received'); const responseTime = require('response-time'); const requestId = require('express-request-id'); const { Signale } = require('signale');
const app = express(); 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 example home page route app.get('/', (req, res) => { req.logger.info('visited home page'); res.send('hello world'); });
// this assumes that you are using passport which
// exposes req.logout to log out the logged in user
app.get('/logout', (req, res) => {
req.logger.warn('logged out');
req.logout();
res.redirect('/');
});
app.listen(3000, () => { cabin.info('app started'); }); ```
In order to easily interact and use the logger utility function exposed by app.use(cabin.middleware), we expose convenient helper methods in Express and Koa:
req.logreq.loggerres.logres.loggerctx.logctx.loggerctx.request.logctx.request.loggerctx.response.logctx.response.loggerThis package requires Promise support, therefore you will need to polyfill if you are using an unsupported browser (namely Opera mini).
We no longer support IE as of Cabin v10.0.0+.
This is the solution for you if you're just using <script> tags everywhere!
<script src="https://cdnjs.cloudflare.com/polyfill/v3/polyfill.min.js?features=Promise"></script>
<script src="https://unpkg.com/cabin"></script>
<script type="text/javascript">
(function() {
var cabin = new Cabin();
cabin.setUser({
id: '1',
email: 'test@example.com',
full_name: 'Test'
});
cabin.info('viewed docs');
})();
</script>
We recommend using https://cdnjs.cloudflare.com/polyfill (specifically with the bundle mentioned in VanillaJS above):
<script src="https://cdnjs.cloudflare.com/polyfill/v3/polyfill.min.js?features=Promise"></script>
This assumes you are using [browserify][], [webpack][], [rollup][], or another bundler.
const Cabin = require('cabin');
const cabin = new Cabin();
cabin.setUser({
id: '1',
email: 'test@example.com',
full_name: 'Test'
});
cabin.info('viewed docs');
$ claude mcp add cabin \
-- python -m otcore.mcp_server <graph>