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

loggerware

v1.1.3

Published

An express middleware for application access and error logs

Downloads

3

Readme

#loggerware

An express middleware for application access and error logs

loggerware listens to every request, logging to STDOUT and STDERR for access and error logging respectively. It does not manipulate any request or response.

##Quick Start

Add the package to your project:

$ npm install loggerware

Require loggerware and register your access and error loggers, like the following*:

var express = require('express'),
    loggerware = require('loggerware')({ name: 'your-logger' }),
    app = express();

app.use(loggerware.register('access', { // Register access loggerware
    file: '/var/tmp/your-access.log'
}));

app.use('/', require('./routes/index'));
app.use('/healthcheck', require('./routes/healthcheck'));
app.use('/oauth', require('./routes/oauth'));

app.use(loggerware.register('error', { // Register error loggerware
    file: '/var/tmp/your-error.log'
}));

app.use(function (err, req, res, next) { // Register error handler
    res.status(err.status || 500);
    if (req.xhr) res.json({ error: err.message });
    else res.render('internal-error');
});

app.listen(port, function () {
    loggerware.info('Server started on http://localhost:%s', port);
});

*Order matters here, for more information on middleware placement goto: http://expressjs.com/en/guide/using-middleware.html

##Guide

####Creating a logger Requiring loggerware will return a method that creates a bunyan logger and exposes extra functionality for creating and registering loggers.

So, executing the following:

var loggerware = require('loggerware')({ name: 'your-logger' });

will give you:

  • loggerware.create create additional loggers for your application
  • loggerware.register register access and error loggers for your application

from here onwards, you have enough of an interface for registering and creating loggers for your application.

If there is a need to, you can create more that one logger by using the loggerware.create method:

var loggerware = require('loggerware')({ 'name': 'your-logger'}),
    loggerA = loggerware.create({ name: 'your-logger-a' }),
    loggerB = loggerware.create({ name: 'your-logger-b' });;

The loggerware.create signature is create([, configuration :: Object]).

  • The optional configuration parameter gets passed to the bunyan.createLogger method. See the bunyan.createLogger api for more details.

####Registering access and error loggers Once you have instantiated a logger, you can register access and error loggers for your application by using the loggerware.register method.

The following registers two loggers to the default logger:

var loggerware = require('loggerware')({ name: 'your-logger' });

loggerware.register('access', {
    name: 'your-access',
    file: '/var/tmp/your-access.log'
});

loggerware.register('error');

In this example we:

  1. created a logger called your-logger
  2. registered an access logger called your-access that streams to STDOUT and to the file /var/tmp/your-access.log
  3. registered an error logger streaming just to STDERR.

The loggerware.register signature is register(type :: String, [, configuration :: Object]).

The type parameter value can either be access or error.

The optional configuration object parameter can consist of format and file keys.

  • The format key specifies the morgan logger format, by default combined is used.
  • The file key specifies the file to log to. If no file key is supplied, your logging will just be streamed to STDOUT and STDERR.

##License MIT