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

node-server-logger

v1.0.3

Published

SPA Node Server Side Logger

Downloads

6

Readme

Server Side Logger

Server-side logging, logs in console by default. In production mode it will send the logs to Kibana via logstash

Installing

Add the module to your dependencies using yarn

npm install node-server-logger --save
yarn add node-server-logger

How to use the logger

Import the logger in your app

import Logger from 'node-server-logger'
const Logger = require('node-server-logger')

Setting up your logger

The logger accepts the following arguments

const logger = Logger('name', 'mode', 'level', {options})
  1. name - string (required) - name of the logger
  2. mode - string (required) - by default is set to development this will log in the browser console. In production the logger will log to Kibana
  3. level - string (required) - the logger follow the bunyan log levels. Setting a logger instance (or one of its streams) to a particular level implies that all log records at that level and above are logged. E.g. a logger set to level "info" will log records at level info and above (warn, error, fatal). At the moment the level need's to be passed as a string but this can (and probably should) be changed to a number in future versions for easier management and testability
  • "error" (50): Fatal for a particular request, but the service/app continues servicing other requests. An operator should look at this soon(ish).
  • "warn" (40): A note on something that should probably be looked at by an operator eventually.
  • "info" (30): Detail on regular operation.
  • "debug" (20): Anything else, i.e. too verbose to be included in "info" level.
  1. 'options' - object (optional)- you can pass the following options:
  • 'logstashHost' - string - a logstash url to send the log's to
  • 'serializers' - object - the logger follows the Bunyan concept of "serializers" to produce a JSON-able object from a JavaScript object, so you can easily do the following:
log.info({ctx: <ctx object>}, 'something about handling this request')

The logger comes with ctx serializer that will serialize the koa context object and will pass the request.method, request.url, response.status, response.header['content-type'] and response.header['content-length']. You can use it like this:

import Logger, { ctxSerializer } from 'rulsoft-server-logger'

// define your logger
const logger = Logger('name', 'console', 'info', {serializers: { ctx: ctxSerializer })

// And then in your logger pass the ctx object like this
logger.info({ctx: ctx}, 'Some info with ctx details')

You can override the default ctxSerializer or you can write your own serializers like this:

import Logger from 'rulsoft-browser-logger'

const someUser = {
// Some object containig data for a user that you want to log
}

function userSerializer(someUser) {
    return {
        name: someUser.name,
        addres: someUser.addres,
        phone: someUser.phone
    }
}

const logger = Logger('someLogger', 'console', 'info', { logstashHost: 'http://logstashHost', serializers: {user: userSerializer} })

logger.info({user: someUser}, 'Something happened')

Running the tests

TODO there are currently no test we will need to add some

Break down into end to end tests

Explain what these tests test and why

Give an example

And coding style tests

Explain what these tests test and why

Give an example

Built With

  • browser-bunyan - This package is an adaptation of, the Node logging library, Bunyan but specifically for the browser.
  • lodash/fp A modern JavaScript utility library delivering modularity, performance & extras.
  • detect-browser This is a package that attempts to detect a browser vendor and version (in a semver compatible format) using a navigator useragent in a browser or process.version in node.

Authors

Velizar Mihaylov