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

loglog-server

v1.0.6

Published

Loglog logging web server

Downloads

4

Readme

Loglog Server

Reads data from a loglog-source and displays in dev tools

Install:

npm install loglog-server

Usage:

You need to setup your own loglog server to execute with node. The loglog-server module simply exposes an express app.

var server  = require('loglog-server');
var auth    = require('http-auth');

// It's necessary to have your datasource set before any requests
// are fulfilled
server.set( 'source', server.sources.mongodb({
  // This configuration should be the same configuration for your
  // loglog-mongodb logging transport
  connection: 'mongodb://host:port/db'
, collection: 'collection_that_stores_logs'
}));

// Need to set url to inform socket.io what to connect to
server.set( 'url', 'https://myhost.com' );

// Custom authentication?
server.set( 'auth', auth.connect( auth.basic({
  realm: "Simon Area.",
  file: __dirname + "/../.htpasswd"
})));

// Listen on port 80
server.listen();

Routes:

GET /           - Real-time log entries
GET /entries?q= - Search entries

REPL API

The primary way to use loglog-server is through the dev-tools REPL. Here are the functions available:

pauseRealtime()

Pauses the real-time logging

resumeRealtime()

Resumes real-time logging

query( queryObj )

Serializes the query object to the loglog-server data source and displays the results in the console.

Returns the URL of the resource

MongoDB Example:

// Display all entries with request id = 123 sort by timestamp desc
query({ where: { 'data.req.id': 123 }, sort: { timestamp: -1 } })

getUrl( [queryObj] )

Returns the URL for a given query object. If no query object is returned, uses the last queryObj passed to query().

Loglog Server Data Sources

A loglog server uses data sources to get logging data from your applications. A source is a factory with the following signature: function ( Object options ) -> Object

The the return object must implement the following methods:

{
  check: function( callback ){ ... } // callback( error, results )
, query: function( query, callback ){ ... } // callback( error, results )
}

The check function is called periodically and should return the only latest log events from the source. So if a previous call to check returned events [1,2,3], then the next call should return those results.

The query function is called when the user is requesting a specific subset of the log history (and likely from within the check function). It's up to the data source as to what format the first parameter takes.

Here's what the mongodb source looks like:

var MongoClient = require('mongodb').MongoClient;

module.exports = function( options ){
  return {
    check: function( callback ){
      var query = {
        where:  this.lastResults.length
                  ? { _id: { $gt: this.lastResults[0]._id } }
                  : {}
      , options: {
          sort: [ [ '_id', -1 ] ]
        , limit: 20
        }
      };

      this.query( query, function( error, results ){
        if ( error ) return callback( error );
        this.lastResults = results;
        return callback( null, results );
      }.bind( this ) );
    }

  , lastResults: []

  , query: function( query, callback ){
      query.where   = query.where || {};
      query.options = query.options || {};

      MongoClient.connect( options.connection, function( error, db ){
        if ( error ) return callback( error );

        var cursor = db.collection(
          options.collection
        ).find( query.where );

        // Options
        [
          'sort', 'skip', 'limit'
        ].forEach( function( option ){
          if ( option in query.options ){
            cursor[ option ]( query.options[ option ] );
          }
        });

        cursor.toArray( function( error, results ){
          db.close();
          callback( error, results );
        });
      });
    }
  };
};