Git Product home page Git Product logo

chrona's Introduction

chrona

Simple HTTP request logger middleware for express.js inspired by koa-logger, written in typescript.

Installation

This is a Node.js module available through the npm registry. Installation is done using the npm install command:

$ npm install chrona

API

var chrona = require('chrona')

app.use(chrona())

Make sure to add chrona to first in middleware chain.

chrona(format, options)

Create a new chrona middleware function using the given format and options. By default, it creates with default format and default options value. The format argument is a string of predefined token names(see below for token names).

Predefined token names.

  • :incoming
  • :[incoming]
  • :remote-address
  • :[remote-address]
  • :date
  • :[date]
  • :method
  • :[method]
  • :url
  • :[url]
  • :http-version
  • :[http-version]
  • :status
  • :[status]
  • :content-length
  • :[content-length]
  • :response-time
  • :[response-time]
  • :referrer
  • :[referrer]
  • :user-agent
  • :[user-agent]

:incoming is special one, If format string contains it, it add directional arrows(-->) for incoming request and outgoing response in log string.

Using a predefined format string

app.use(chrona(":incoming :method :url :status :response-time :content-length :user-agent :http-version"))

options

chroma accepts options argument as a function or an object. Right now chroma has only one option call transporter which can be provided either by passing function or an object with transporter key. Transporter is for change chrona's default transporter(where to show log messages) which is console.log.

Use Custom Transporter

// If you want to go with default format string, then just pass
// empty string or null
app.use(chrona(null, function(str, args) => {
    // pass str and args to your own transporter like winston etc.
}))

chrona's People

Contributors

xambassador avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 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.