Code Monkey home page Code Monkey logo

morgan-lwes's Introduction

morgan-lwes NPM version Build Status

Logging middleware for node.js http apps, which emits LWES events instead of logging to disk.

Based on as forked from morgan.

API

var express = require('express');
var emitter = require('morgan-lwes');

var app = express();
app.use(emitter());
Sample Event

This is a sample event when using the setup above.

{ type: 'MorganLWES::Logger',
  attributes:
   { status: '200',
     referrer: '-',
     user_agent: 'Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0',
     response_time: '0.683',
     response_content_length: '12',
     method: 'GET',
     remote_addr: '127.0.0.1',
     date: 'Wed, 11 Jun 2014 23:00:37 GMT',
     url: '/',
     http_version: '1.1' } }
{ type: 'MorganLWES::Logger',
  attributes:
   { status: '404',
     referrer: '-',
     user_agent: 'Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0',
     response_time: '0.265',
     response_content_length: '-',
     method: 'GET',
     remote_addr: '127.0.0.1',
     date: 'Wed, 11 Jun 2014 23:00:37 GMT',
     url: '/favicon.ico',
     http_version: '1.1' } }

options

MorganLWES may be passed options to configure the tokens which are emitted. The options may be passed as a predefined list of tokens, token list, or function.

morgan() // default
morgan('short')
morgan('tiny')
morgan({ format: 'short', immediate: true })
morgan([':method', ':url', ':referrer'])
morgan([':request[content-type]', ':response[content-type]'])
morgan(function(tokens, req, res){ return { data: 'some format string', status: res.statusCode } });
morgan({ format: 'tiny', skip: function(req, res){ return res.statusCode === 304; }});

Predefined Formats

  • default - Standard output.
  • short - Shorter than default, also including response time.
  • tiny - The minimal.

Options

MorganLWES accepts these properties in the options object.

  • format - Format string or Setting, see below for format tokens.
  • emitter - Custom emitter, defaults to built in emitter. (Mostly for testing.)
  • lwes - Object containing lwes configurations for new liblwes.Emitter(...).
    • type - Emitted type field, default MorganLWES::Logger.
    • address - Address to emit on, default 127.0.0.1.
    • port - Port to emit on, defaults to 1111.
    • esf - Path on disk to ESF file, defaults to undefined.
  • immediate - Write log line on request instead of response (for response times).
  • skip - Function to determine if logging is skipped, called as skip(req, res), defaults to false.

All default formats are defined this way, however the api is also public:

morgan.format('name', 'array or function')

Tokens

  • :request[header] ex: :request[Accept]
  • :response[header] ex: :response[Content-Length]
  • :http-version
  • :response-time
  • :remote-addr
  • :date
  • :method
  • :url
  • :referrer
  • :user-agent
  • :status

To define a token, simply invoke morgan.token() with the name and a callback function. The value returned is then available as ":type" in this case:

morgan.token('type', function(req, res){ return req.headers['content-type']; })

TODO

  • Add esf examples for preformatted setting -- default, short and tiny.

License

The MIT License (MIT)

Copyright (c) 2014 Joshua P. Mervine [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

morgan-lwes's People

Contributors

dougwilson avatar fishrock123 avatar jonathanong avatar

Watchers

 avatar  avatar  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.