Coder Social home page Coder Social logo

mrjackdavis / morgan-body Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sirrodgepodge/morgan-body

0.0 1.0 0.0 105 KB

A highly configurable Express logger that logs request and response body and is nicely colorized for your terminal :)

License: MIT License

JavaScript 100.00%

morgan-body's Introduction

morgan-body

So frequently in Dexter and the "morgan" library, we are left wondering, where's the body?

Well, we've found it!
(for "morgan" library, not the show :P)

Here is logging the way you always wanted it to be!
Nicely colorized logging that includes Request and Response bodies.

(Now with Typescript support thanks to @francisbrito)

NPM

Example Use

Note: unlike typical express middleware you must pass the actual app into the function

import morganBody from 'morgan-body';
import express from 'express';
import bodyParser from 'body-parser';

const app = express();

// must parse body before morganBody as body will be logged
app.use(bodyParser.json());

// hook morganBody to express app
morganBody(app);

screen shot 2017-07-07 at 2 02 55 am

*Note: console output is colorized for iTerm2, might look odd on terminals with other background colors

API

morganBody(<express instance>, <options object>)

Options are:

{
  noColors: (default: false), gets rid of colors in logs, while they're awesome, they don't look so good in log files as @rserentill pointed out

  maxBodyLength: (default: 1000), caps the length of the console output of a single request/response to specified length,

  prettify: (default: true), prettifies the JSON request/response body (may want to turn off for server logs),

  logReqDateTime: (default: true), setting to false disables logging request date + time,

  dateTimeFormat: (default: 'utc', available: ['edt', clf', 'iso', 'utc']), lets you specify dateTime format logged if "logDateTime" option is true (otherwise dateTime not logged anyways)

  timezone: (default : server's local timezone), time will be logged in the specified timezone. e.g. "EST", "America/Los_Angeles", "Asia/Kolkata" (for Indian Standard Time), etc. Internally uses "momentjs" for interpreting the timezone, and if specified value is not understood by momentjs, falls back to using the local timezone. (Please have a look at the TZ column here for a lit of supported timezone strings: https://wikipedia.org/wiki/List_of_tz_database_time_zones#List).

  logReqUserAgent: (default: true), setting to false disables logging request user agent,

  logRequestBody: (default: true), setting to false disables logging request body,

  logResponseBody: (default: true), setting to false disables logging response body,

  skip: (default: null), optionally provide function of the signature "(req, res) => <bool>" to conditionally skip logging of requests (if provided function returns true),

  stream: (default: null), optionally provide a stream (or any object of the shape { write: <Function> }) to be used instead of "process.stdout" for logging to,

  theme: (default: 'defaultTheme'), alter the color scheme of your logger with a theme, see available themes below
}

Available Themes

Can be passed in as "theme" option, screenshots taken in iTerm2 (note that some text is not visible in some screenshots, this is because this text is colored non-intense black, it would show up on white-background terminals).

defaultTheme

screen shot 2018-06-30 at 11 40 31 pm

dracula

screen shot 2018-06-30 at 11 37 32 pm

usa

screen shot 2018-06-30 at 11 14 48 pm

inverted

reverse ASCII color of default screen shot 2018-07-01 at 12 03 57 am

darkened

no white (all colors rotated one away from white) screen shot 2018-06-30 at 11 24 42 pm

lightened

no black (all colors rotated one away from black) screen shot 2018-07-01 at 12 06 48 am

dimmed

only non-"intense" colors screen shot 2018-07-01 at 12 05 35 am

morgan-body's People

Contributors

sirrodgepodge avatar natezmatthews avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.