npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

connect-ltsv-logger

v0.0.2

Published

ltsv formated access logger for connect based application

Downloads

6

Readme

Introduction

LTSV format logger for (connect|express).

This is just a wrapper of connect.middleware.logger.

Usage

var express = require("express"),
    ltsvlogger = require('connect-ltsv-logger');

// define output WriteStream
var out = fs.createWriteStream("ltsv-access.log",{flags: 'a+'}),

// define tokens
var ltsv = [];
ltsv.push("host");
ltsv.push("ident");
ltsv.push("user");
ltsv.push("time");
ltsv.push("req");
ltsv.push("status");
ltsv.push("size");
ltsv.push("referer");
ltsv.push("ua");

var app = express();
app.configure(function(){
	// app.set(/*snip*/)
	// ...

	app.use(ltsvlogger({format:ltsv,stream:out}));

	// app.use(/*snip*/)
	// ...
});
tail -f ltsv-access.log
host:127.0.0.1<TAB>ident:-<TAB>user:-<TAB>time:[13/Feb/2013:19:15:44 +09:00]<TAB>req:GET /stylesheets/style.css HTTP/1.1<TAB>status:200<TAB>size:110<TAB>referer:http://localhost:3001/<TAB>ua:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.57 Safari/537.17

Options

  • format: Format string or Token array, see below for tokens
  • stream :is the same as connect.logger.
  • buffer: is the same as connect.logger.
  • immediate: is the same as connect.logger.

Formats

Just override connect.logger's formats as ltsv

  • default

host:127.0.0.1<TAB>ident:-<TAB>user:-<TAB>time:[Wed, 13 Feb 2013 10:00:55 GMT]<TAB>req:GET / HTTP/1.1<TAB>status:200<TAB>size:110<TAB>referer:-<TAB>ua:-

  • short

host:127.0.0.1<TAB>ident:-<TAB>req:GET / HTTP/1.1<TAB>status:200<TAB>size:-<TAB>response-time:1 ms

  • tiny

req:GET /<TAB>status:200<TAB>size:-<TAB>response-time:1 ms

  • dev

concise output colored by response status for development use (Not ltsv format).

Tokens

The following tokens are available

  • time

    logger.token("time",function(){
      return "[" + moment().format("DD/MMM/YYYY:HH:mm:ss Z") + "]" ;
    });
  • host

    logger.token("host",function(req,res){
      return req.connection.address().address || '-';
    });
  • X-Forwarded-For

    logger.token("X-Forwarded-For",function(req,res){
      return res.getHeader("X-Forwarded-For") || "-";
    });
  • user

    logger.token("user",function(req,res){
      return '-';
    });
  • ident

    logger.token("ident",function(req,res){
      return '-';
    });
  • req

    logger.token("req",function(req,res){
      var ret = [];
      ret.push(req.method);
      ret.push(req.url);
      ret.push("HTTP/"+req.httpVersion);
      return ret.join(" ");
    });
  • method

    logger.token("method",function(req,res){
      return req.method;
    });
  • uri

    logger.token("uri",function(req,res){
      return url.parse(req.url).href;
    });
  • protocol

    logger.token("protocol",function(req,res){
      return url.parse(req.url).protocol;
    });
  • status

    logger.token("status",function(req,res){
      return res.statusCode;
    });
  • size

    logger.token("size",function(req,res){
      return res.getHeader("content-length");
    });
  • reqsize

    logger.token("reqsize",function(req,res){
      if(req.body) return req.body.length;
      return "-";
    });
  • referer

    logger.token("referer",function(req,res){
      return req.headers['referer'] || req.headers['referrer'];
    });
  • ua

    logger.token("ua",function(req,res){
      return req.headers['user-agent'];
    });
  • vhost

    logger.token("vhost",function(req,res){
      return req.headers["host"];
    });
  • reqtime

    logger.token("reqtime",function(req,res){
      return new Date - req._startTime;;
    });
  • X-Cache

    logger.token("X-Cache",function(req,res){
      return res.getHeader('X-Cache');
    });
  • X-Runtime

    logger.token("X-Runtime",function(req,res){
      return res.getHeader('X-Runtime');
    });

Install

npm do

npm install connect-ltsv-logger

License

Source code can be found on github, licenced under MIT.

Author

Developed by Takeharu.Oshida