Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cabin

Package Overview
Dependencies
Maintainers
1
Versions
124
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cabin

Cabin is a logging/analytics service and middleware for Node.js, Lad, Koa, Express, and Passport

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.2K
decreased by-28.66%
Maintainers
1
Weekly downloads
 
Created
Source

cabin

chat build status code coverage code style styled with prettier made with lass license

Cabin is a logging/analytics service and middleware for Node.js, Lad, Koa, Express, and Passport.
Frustrated with Sentry, Timber, Airbrake, Papertrail, or Bugsnag? We were too! • Built by @niftylettuce and contributors

Cabin is in alpha development, join us in Slack. Our web-based dashboard will be available soon!

Table of Contents

Install

npm:

npm install cabin

yarn:

yarn add cabin

Usage

Don't want to configure this yourself? You can simply use Lad which has this all built-in for you already!

  1. Simply include the middleware and pass options if needed

  2. Use ctx.log(level, message, meta) (Koa) or req.log(level, message, meta) (Express) to log messages anywhere in your app middleware functions.

  3. You can also use shorthand method level calling, such as ctx.log.debug(msg, meta), ctx.log.info(msg, meta), ctx.log.warn(msg, meta), or ctx.log.error(msg, meta) for Koa (and req.log equivalents for Express), which automatically populate the level argument with the respective level.

Koa

const Koa = require('koa');
const Cabin = require('cabin');

const app = new Koa();
const cabin = new Cabin();

// use the cabin middleware
app.use(cabin.middleware);

// add your user/session management middleware here (e.g. passport)

// this assumes that you are using passport which
// exposes `ctx.logout` to log out the logged in user
app.get('/logout', ctx => {

  ctx.log.warn('Logged out');
  // you could also use aliases:
  // `ctx.log('warn', 'Logged out')`
  // `ctx.logger.warn('Logged out')`
  // `ctx.logger('warn', 'Logged out')`

  ctx.logout();
  ctx.redirect('/');
});

// you can also use it to log activity such as user checking out
app.listen(3000);

Express

const express = require('express');
const Cabin = require('cabin');

const app = express();
const cabin = new Cabin();

// use the cabin middleware
app.use(cabin.middleware);

// add your user/session management middleware here (e.g. passport)

// this assumes that you are using passport which
// exposes `req.logout` to log out the logged in user
app.get('/logout', (req, res) => {

  req.log.warn('Logged out');
  // you could also use aliases:
  // `req.log('warn', 'Logged out')`
  // `req.logger.warn('Logged out')`
  // `req.logger('warn', 'Logged out')`

  req.logout();
  res.redirect('/');
});

app.listen(3000);

Options

  • logger (Object) - defaults to console (you might want to use something like Lad's logger)
  • userFields (Array) - defaults to [ 'id', 'email', 'full_name'] - these are the default fields to store from a parsed user object

Metadata

By default all users (even ones not logged in) will have a user object stored in the log metadata with their IP address stored as user.ip_address.

If a logged in user is detected (e.g. if you're using Passport), then we add to the log metadata user object the properties and user's respective values (if any) for each value specified in the userFields option.

Also we add to log metadata by default a request object with HTTP method, query_string, headers, cookies, body (request body safe stringified using fast-safe-stringify), and url properties.

Are we missing something? If so let us know by emailing niftylettuce@gmail.com or filing an issue on GitHub.

Contributors

NameWebsite
Nick Baughhttp://niftylettuce.com/

Trademark Notice

Lad, Lass, Cabin, Lipo, and their respective logos are trademarks of Niftylettuce LLC. These trademarks may not be reproduced, distributed, transmitted, or otherwise used, except with the prior written permission of Niftylettuce LLC. If you are seeking permission to use these trademarks, then please contact us.

License

MIT © Nick Baugh

#

Keywords

FAQs

Package last updated on 01 Jun 2018

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc